Comments (10)
Any solution to this please?
Facing the same issue
from electron-dl.
@integemjack can you provide a description of the error?
I am trying the following:
ipcMain.on('download-request', async (event, {url}) => {
console.log('requesting to download', url);
try {
const win = BrowserWindow.getFocusedWindow();
await download(win, url);
}
catch (e) { console.error('(download)', e); }
});
and I'm getting this popup:
Uncaught Exception:
TypeError: Cannot read properties of null (reading 'getOwnerBrowserWindow')
at Function.n.fromWebContents (node:electron/js2c/browser_init:33:1573)
at Session.listener (/Users/corwin/var/workspace/Teaching.Web.GR/node_modules/electron-dl/index.js:68:64)
at Session.emit (node:events:406:35)
The exception is not caught by my try .. catch
because apparently it occurs in a tasklet.
from electron-dl.
@integemjack can you provide a description of the error?
I am trying the following:
ipcMain.on('download-request', async (event, {url}) => { console.log('requesting to download', url); try { const win = BrowserWindow.getFocusedWindow(); await download(win, url); } catch (e) { console.error('(download)', e); } });and I'm getting this popup:
Uncaught Exception: TypeError: Cannot read properties of null (reading 'getOwnerBrowserWindow') at Function.n.fromWebContents (node:electron/js2c/browser_init:33:1573) at Session.listener (/Users/corwin/var/workspace/Teaching.Web.GR/node_modules/electron-dl/index.js:68:64) at Session.emit (node:events:406:35)
The exception is not caught by my
try .. catch
because apparently it occurs in a tasklet.
const win
is for sure null
. That is why you get this error.
from electron-dl.
Thanks for the reply. But that's exactly what the docs say:
https://github.com/sindresorhus/electron-dl#use-it-manually
Which also worked with a previous version of Electron, and this is why I attached my excerpt to this issue.
Why would BrowserWindow.getFocusedWindow
return null?
I went ahead and printed it. It is not null.
from electron-dl.
I use latest electron-dl and Electron in my project. No issue so far.
Sample code
win is injected through function parameter, not with getFocusedWindow
import dl from 'electron-dl'
void dl.download(this.win, mod.url, {
filename: mod.name,
onStarted: item => {
modToUse = this.updateDownloadInStore(modToUse, {
localFilePath: item.getSavePath(),
})
this.addDownloadInStore(modToUse, item)
this.setPreviousTime(modToUse)
this.startInterval(mod.id)
resolve(modToUse)
},
onProgress: () => {
this.sendIpcEvents.progressModDownload(this.modDownloadStore.get())
},
onCompleted: () => {
modToUse = this.updateDownloadInStore(modToUse, {
state: DownloadState.finish,
downloadedSize: mod.size,
})
this.sendIpcEvents.finishModDownload(this.modDownloadStore.get())
this.deletePreviousTime(modToUse)
},
})
})
this.win: BrowserWindow
mod.url: string
from electron-dl.
@Kiyozz thanks, but what is this.win in your case? Is this code part of a class definition (since you are using this
)?
from electron-dl.
Class method
startDownloadOfMod(mod: BaseModDownload): Promise<BaseModDownload> {
// ...
return new Promise<BaseModDownload>(resolve => {
void dl.download(this.win, mod.url, {
filename: mod.name,
onStarted: item => {
modToUse = this.updateDownloadInStore(modToUse, {
localFilePath: item.getSavePath(),
})
this.addDownloadInStore(modToUse, item)
this.setPreviousTime(modToUse)
this.startInterval(mod.id)
resolve(modToUse)
},
})
})
}
Class constructor
constructor(
private http: HttpManager,
private modDownloadStore: ModDownloadStore,
private win: BrowserWindow,
private sendIpcEvents: SendIpcEvents,
) {}
So in my main file, I create the window. I use a function I called initialize
.
await initialize(win)
In initialize
, I create the instance and I inject it.
const downloadManager = new DownloadManager(
httpManager,
modDownloadStore,
win,
sendIpcEvents,
)
from electron-dl.
Can anyone try this with their code base? (I kind of stopped using electron-dl in my code as a result of this issue; @OfekA-IAI, @sKY02644, perhaps?)
from electron-dl.
You can use :
BrowserWindow.getAllWindows()[0]
or
BrowserWindow.fromId(1)
instead of BrowserWindow.getFocusedWindow() to retrieve the root window
from electron-dl.
I encountered the same issue. It turned out to be the url passed to download function.
I was passing the url without the origin (https://hostname). I was passing in just the path (/path/to/file/to/download) without the origin.
I Later changed to pass in the full url (https://hostname:port/part/to/file/to/download.
This is what worked for me
from electron-dl.
Related Issues (20)
- Cannot find n ame 'Completed'. (new in 3.2) HOT 1
- Utilizing session.enableNetworkEmulation with ElectronDL HOT 1
- TypeError upon evaluation of download() arguments HOT 1
- Overwrite Option is flase. but, the same file name is specified in the directory, it is overwritten. HOT 2
- Status of tests and remote module HOT 1
- Downloads stuck on MacOS HOT 5
- Cannot read property 'getType' of null at getWindowFromWebContents
- cannot read 'getOwnerBrowserWindow' HOT 1
- Save-as dialog shows two periods before the SQLite file extension in the file type filter
- Property defination are different between index.d.ts and index.js
- Download URL with POST requests. HOT 1
- is there any sample project i can't make
- how can i make progress bar please help HOT 1
- When I change menu in navbar with route, it goes into loop
- how to post a json param
- Self signed certificate download not working.
- Get "Download Error" when using save as dialog and cancel button is pressed HOT 1
- Electron 30 support HOT 6
- Download start even `Save as` not appear
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from electron-dl.