-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Cannot assign to read only property 'onbeforeunload' of object '#<Window>' #1082
Comments
Similar problem here. Have you found a solution? |
Using old nightmare is just a temporary solution. |
I experienced a |
Care to share your workaround code? |
@entrptaher It might not work under all circumstances
|
+1 same here with 2.10.0 |
I found a workaround
|
This is a regression introduced by #825 . The fix is trivial. The preload.js script needs to be modified to: // prevent 'onunload' and 'onbeforeunload' from being set
Object.defineProperties(window, {
onunload: {
enumerable: true,
writable: true,
value: null,
set: function() {}
},
onbeforeunload: {
enumerable: true,
writable: true,
value: null,
set: function() {}
}
}); Perhaps someone else would be so kind as to put this into a PR? :-) |
+1 same here with 2.10.0 |
@bwbuchanan, I tried putting that preload.js, |
I tested your solution, @bwbuchanan. And the result is as you can see. Codes:
This worked which is similar to @w01fgang solution:
Maybe we can turn this into a plugin/action. |
You must have a different version of something than I do. Try removing "value: null" and replacing with "get: function() { return null; }" Simply making it writable defeats the purpose of #825 |
I can confirm that setting the below values to @matthewmueller Would you accept a pull request with these changes to the preload script? Would this change brake the other resolved issue previously mentioned above? If so, then I think this shouldn't be part of the default preload script at all. What do you think? |
This happened to me with 3.0.1 just now, just fyi edit: @kireerik's solution fixed it for me :) thanks! |
The way to avoid this problem:
Step 2: When you init nightmare, webPreferences.preload uses files that have just been modified.
|
This issue is apparently pretty old but I ran into the same problem. It appears the fix is simple, although modifying preload.js manually is not a viable solution for automated testing |
segment-boneyard/nightmare#825 broke being able to set beforeonload events. see: segment-boneyard/nightmare#1082
Today I ran into the same issue. It doesn't work! And when I change writable to true I get |
When I downgrade to Nightmare 2.8.1 - I can edit writable. But in the newest version I cannot :( |
…unload' of object '#<Window>' segment-boneyard#1082
Any script I Run through medium.com does not work. The site does not load properly. If I open devtools, I can see an error, This error does not happen with normal browsers.
I am using latest nodejs, nightmarejs and electron.
The code I am using simply goes to the site so I can check what went wrong.
Error on version 2.9.0 or above
No error on nightmare 2.8.0 (which uses electron-prebuilt)
The text was updated successfully, but these errors were encountered: