Chrome extension throwing a “Cannot convert undefined or null to object” error#738
Chrome extension throwing a “Cannot convert undefined or null to object” error#738alfreddagenais wants to merge 1 commit intoelectron-userland:masterfrom
Conversation
|
@alfreddagenais thank you for this patch, it helps resolve the issue locally. Expanding upon this, according to this stackoverflow issue, the electron.remote is only available if call(s) to new BrowserWindow are extended with the following parmeter:
I confirmed this locally, if I modify my application such that the main window is created w/ this parameter the error disappears, no hotfix is needed. The issue is that many will not be able to enable the remote module (it entails security implications and is against electron security guidelines. Your hotfix works as an interim solution for the time being but does entail various side-effects, namely various BrowserWindow and WebContents methods will not be available in the spectron API and perhaps more importantly the spectron Application 'stop' method will not actually stop the application. In the original (premodified) implementation, the stop method delegates to electron.remote.app.quit which actually quits the application but in your patch, this is stubbed out and the resolve/reject methods are manually called. All in all great addition, though others should be aware of the tradeoffs until we figure out a solution that works in all cases (ideally spectron should not depend on the remote module, but not sure if this is possible) |
|
@movitto I was about to go crazy thank you for your comment! |
When I try to start Spectron, i got a
javascript error: javascript error: Cannot convert undefined or null to objectin the consoleTo debug this i search lot where can be. I finally found the way to reproduce that error.
Install Debugging tools in VS Code
I install Debugging tests in VS Code tools to help me with this debugging.
Start Debugging
I try to add many break points to find the possible error.
The breakpoint they was the more useful :
fullRequestOptionsI finally found Spectron send Chromedrive debug some functions and the Chromedrive callback. And for this last call back Chromedrive send the
javascript error: Cannot convert undefined or null to objectWhen you check into this request, you will find the URL use for this request 👍
The URL we got is
http://127.0.0.1:9515/session/{{session_name}}/execute/sync. Thesession_nameis a random session UIDSo go back to the
fullRequestOptionsand you will see the exact request send to the debug toolAnd next we found these 2 parameters were sent
Try to investigate
I open my Postman application and I try to send POST request with the same parameters.
Bam!!! We have the error

Correct the error
I finally found
electron.remotenot initiated at the point of the code. So I simply add the code to protect this andet voilà!