-
Notifications
You must be signed in to change notification settings - Fork 15k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
webview setting baseURLForDataURL crashes Electron #20700
Comments
It's not the webview only specific. It crashed even if you call A quite severe issue. @sofianguy hope it gets moved |
This bug is occuring for me too in v7.0.0. However you said |
Works for me in 6.0.10 (no crhash and rendering is ok), but for regular window, didn't try the webview. Electron 8-beta1 is also affected. |
no, works as expected in 6.0. Maybe you can open another issue with a repo? |
Thanks for the quick replies @vladimiry and @burningTyger. I've cloned your webview-bug repo and although you code does indeed run in 6.0.10, if you change baseURLForDataURL to an HTTP URL then it fails (the program doesn't crash but the webview doesn't render at all), even in version 6.0. For example this is what I have changed the code to: let webview = document.querySelector('webview');
webview.addEventListener('dom-ready', () => {
webview.loadURL(
`data:text/html;charset=utf-8;base64,
PGgxPkhBTExPPC9oMT4=
`, { baseURLForDataURL: `https://github.com/` })
//This will fix the issue:
// `)
}) Electron version 5.0.0-beta.2 is the last version in which this works. Though perhaps this is a seperate bug, I can write up a new issue for this if the maintainers would like me to? |
@sofianguy v8 also crashes, can you add a respective label? |
* TODO (switch back to upstream "node-spellchecker") atom/node-spellchecker#127 * TODO (blocker) electron/electron#20700 * TODO (blocker @electron v8) electron/electron#21154
I encountered a similar problem with BrowserWindow. const { app, BrowserWindow } = require('electron');
app.on('ready', () => {
new BrowserWindow().loadURL(
'data:text/html;charset=UTF-8,' + encodeURIComponent('<script src="test.js"></script>'),
{ baseURLForDataURL: 'C:/Users/xxx/Documents/' }
);
}); Where test.js only contains Without the Thanks in advance for any help |
Just tried the recently released v8-beta3. The problem is still there, the app crushes.
|
A little work around. If you register your own file protocol (@see https://electronjs.org/docs/api/protocol) and use that as the baseURLForDataURL the crashing stops and you can access your files.
Of course this doesn't solve the crashing problem. :-/ |
Can confirm the custom protocol workaround is functional, just tested it on v8-beta3, thanks @marvin-martian. |
It stops the crashes for me but in my webviews I now can't access further assets for which I need the |
@burningTyger I simply exposed the specific directory in the app path via file protocol https://github.com/vladimiry/ElectronMail/blob/6135622cf73d11e783204074734016453fdcc64c/src/electron-main/protocol.ts#L32-L60 I didn't try using other/non-file protocol types as a workaround, might also work. |
@sofianguy I also tested this issue with platfom/mac and electron 8 beta and it also fails. Maybe the tags can be added as well? |
+1 confirmed, any ideas what's causing this? |
@burningTyger Here's the code I tried and it works by using the file protocol hack.
Just copy paste it in your |
@catalin-luntraru I appreciate the help but this might work for |
It does work with webviews, here https://github.com/vladimiry-playground/electron-quick-start-baseURLForDataURL |
@vladimiry super hero! I tried right after you posted and it failed again. Today I was going to try for real and I noticed I had copied the |
Thanks go to @marvin-martian who revealed the workaround. The issue was a blocker for me but the workaround allowed upgrading the electron version. |
Can confirm the workaround with electron v8.0.0 const { app, BrowserWindow, protocol } = require('electron');
const path = require('path');
app.on('ready', () => {
protocol.registerFileProtocol('el', (request, callback) => {
callback({ path: path.normalize(decodeURIComponent(request.url.substr(3))) });
});
new BrowserWindow().loadURL(
'data:text/html;charset=UTF-8,' + encodeURIComponent('<script src="test.js"></script>'),
{ baseURLForDataURL: 'el://C:/Users/xxx/Documents/' }
);
}); It now works fine. |
One thing I notice though is that the devtools fail to load maps: |
electron 8 rendering process will not report an error using require ()? |
This bug is also not unique to linux despite the tags on this issue. I'm experiencing it on mac with electron 7.1.3. I also tried going back to v6 which as mentioned by @evanrolfe, does not cause a crash but instead causes an ERR_FAILED loading error which results in a blank webview. |
Also experiencing this on Windows 10 with 8.2.2 |
This probably occurs because nodeIntegration was not enabled in my example. Try to use this object as parameter for the BrowserWindow constructor: {webPreferences:{nodeIntegration:true}} |
Also experiencing this on Ubuntu with 9.0.0 |
In its latest iteration (9.0.x) this bug also requires me to serve other files from subsequent pages with the new prefix. This bug seems only to appear on Windows. On macOS it works without explicitly setting the prefix (e.g. Just in case someone encouters the |
Just ran into this issue. As a workaround, I'm injecting the https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base |
This is still broken in electron 10 please say this will be fixed at some point as it would be really useful to have it working correctly |
$50 via any payment method to whoever fixes this |
Still seem to be an issue on electron v11.1.1, but as mentionned above, making a custom file protocol fix the problem : const customProtocol = 'file2';
protocol.registerFileProtocol(customProtocol, (request, callback) => {
const url = request.url.substr(customProtocol.length + 2);
const file = { path: path.normalize(`${__dirname}/${url}`) }
callback(file)
});
let win = new BrowserWindow({
webPreferences: {
nodeIntegration: true,
contextIsolation: true
}
})
win.loadURL(`data:text/html;charset=UTF-8,${encodeURIComponent(indexHTML)}`, {
baseURLForDataURL: `${customProtocol}://${app.getAppPath().replace("\\", "/")}/`
}); |
A quick (and unsafe) fix I found on v10.1.1 is to run This lets you set the |
Registering a custom protocol and require a module with a relative path will be failed stil. try {
result = _require(_path);
} catch(error) {
result =
_require(path.join(path.dirname(document.baseURI), _path).replace('file:', ''));
} |
Duplicate of #28407 |
@nornagon And this issue points to the more general issue in that baseURLfoDataURL is broken. Having work arounds is not fixing the broken issue. |
I've marked this issue as a duplicate of #28407 because they share the same underlying cause, and because that issue has more information about that cause. |
@nornagon I set up a Electron Fiddler of the portion of this problem that doesn't use a custom protocol and thus doesn't overlap with #28407 but still crashes: https://gist.github.com/7c979306285b7b8a4588261663ce5a8b Maybe we could re-open this issue for that use case? |
Preflight Checklist
Issue Details
Expected Behavior
Opening a
webview
with a preset source as in:loads the github URL and then reloads the webview with
HALLO
.Actual Behavior
Electron crashes
To Reproduce
See this repo:
https://github.com/burningTyger/webview-bug
Screenshots
Additional Information
The text was updated successfully, but these errors were encountered: