Skip to content
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

Breaking 5.0 change: process is undefined when using browserWindow.loadURL(url) #17967

Closed
OiYouYeahYou opened this issue Apr 25, 2019 · 4 comments · Fixed by #17971
Closed

Breaking 5.0 change: process is undefined when using browserWindow.loadURL(url) #17967

OiYouYeahYou opened this issue Apr 25, 2019 · 4 comments · Fixed by #17971

Comments

@OiYouYeahYou
Copy link

Issue Details

  • Electron Version: 5.0.0
  • Operating System: Ubuntu 18.10 (Cosmic Cuttlefish)
  • Last Known Working Electron version:: ^3 and ^4

Expected Behavior

process to be defined inside browser window

Actual Behavior

process is undefined inside browser window

To Reproduce

app.html

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <script>console.log(process)</script>
</body>

</html>

main.js

const { app, BrowserWindow } = require('electron')

app.on('ready', () =>
    Promise.resolve().then(() => {
        let mainWindow = new BrowserWindow({
            contextIsolation: false,
            nodeIntegration: true,
            webviewTag: true,
        })

        mainWindow.loadURL(`file://${__dirname}/app.html`)

        mainWindow.on('closed', () => (mainWindow = null))
    })
)

package.json

{
  "name": "elec-break-5",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "dependencies": {
    "electron": "^5.0.0"
  }
}

Screenshots

image

Additional Information

This is working in v^3 and v^4, but causes issues in v5. Nor have there been any depreciation warnings in v4 and nothing is referenced in breaking changes

@kwonoj
Copy link
Contributor

kwonoj commented Apr 25, 2019

breaking changes explains nodeIntegration set to false which is for this case, isn't it?

@OiYouYeahYou
Copy link
Author

@kwonoj I believe the webPreferences are to their pre-v5 defaults in the main.js?

let mainWindow = new BrowserWindow({
  contextIsolation: false,
  nodeIntegration: true,
  webviewTag: true,
})

@kwonoj
Copy link
Contributor

kwonoj commented Apr 25, 2019

I'm on v4 currently and it is under webPreferences. which fits with v4's documentation as well. https://github.com/electron/electron/blob/v4.1.5/docs/api/browser-window.md

and breaking changes are setting its default value true to false which explains this specific.

@OiYouYeahYou
Copy link
Author

Ok, SO, the actual fix is as follows

let mainWindow = new BrowserWindow({
	webPreferences: {
		nodeIntegration: true,
	},
})

Could the breaking docs be a little clearer? Like including code example like previous versions?

MarshallOfSound added a commit that referenced this issue Apr 26, 2019
* docs: add example on handling the webPrefs change

Fixes #17967

* Update breaking-changes.md
kiku-jw pushed a commit to kiku-jw/electron that referenced this issue May 16, 2019
* docs: add example on handling the webPrefs change

Fixes electron#17967

* Update breaking-changes.md
codebytere pushed a commit that referenced this issue Jun 18, 2019
* docs: add example on handling the webPrefs change

Fixes #17967

* Update breaking-changes.md
codebytere added a commit that referenced this issue Jun 18, 2019
* docs: add example on handling the webPrefs change

Fixes #17967

* Update breaking-changes.md
trop bot pushed a commit that referenced this issue Jun 18, 2019
* docs: add example on handling the webPrefs change

Fixes #17967

* Update breaking-changes.md
codebytere pushed a commit that referenced this issue Jun 19, 2019
* docs: add example on handling the webPrefs change

Fixes #17967

* Update breaking-changes.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants