{"action":"opened","issue":{"url":"https://api.github.com/repos/electron/electron/issues/7814","repository_url":"https://api.github.com/repos/electron/electron","labels_url":"https://api.github.com/repos/electron/electron/issues/7814/labels{/name}","comments_url":"https://api.github.com/repos/electron/electron/issues/7814/comments","events_url":"https://api.github.com/repos/electron/electron/issues/7814/events","html_url":"https://github.com/electron/electron/issues/7814","id":186379682,"number":7814,"title":"vm.runInNewContext() & console.log causes devtools to disconnect","user":{"login":"michaelbromley","id":6275952,"avatar_url":"https://avatars.githubusercontent.com/u/6275952?v=3","gravatar_id":"","url":"https://api.github.com/users/michaelbromley","html_url":"https://github.com/michaelbromley","followers_url":"https://api.github.com/users/michaelbromley/followers","following_url":"https://api.github.com/users/michaelbromley/following{/other_user}","gists_url":"https://api.github.com/users/michaelbromley/gists{/gist_id}","starred_url":"https://api.github.com/users/michaelbromley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/michaelbromley/subscriptions","organizations_url":"https://api.github.com/users/michaelbromley/orgs","repos_url":"https://api.github.com/users/michaelbromley/repos","events_url":"https://api.github.com/users/michaelbromley/events{/privacy}","received_events_url":"https://api.github.com/users/michaelbromley/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-10-31T19:49:23Z","updated_at":"2016-10-31T19:49:23Z","closed_at":null,"body":"* Electron version: 1.4.3\r\n* Operating system: Windows 10 x64\r\n\r\nI am building an app which runs user scripts in a sandboxed environment, so I want to use the Node vm module. Here is the code I use to load the user scripts:\r\n\r\n```TypeScript\r\nfunction runInSandbox(visPath: string): IVisualization {\r\n    let context = {\r\n        require: (moduleName) => {\r\n            // I implement a custom \"safe\" require method here\r\n        },\r\n        console: console,\r\n        module: {}\r\n    };\r\n    let data = fs.readFileSync(path.join(visPath, 'index.js'));\r\n    let result = vm.runInNewContext(data, context, { visPath });\r\n    return result;\r\n}\r\n```\r\n\r\n```JavaScript\r\n// userscript/index.js\r\nconsole.log('test');\r\n```\r\n\r\nNow, when I run the app without devtools open, the user scripts execute as expected. However, when I am running with the devtools open, as soon as one of the user scripts does a `console.log`, the devtools crashes with:\r\n\r\n```\r\nDevTools was disconnected from the page.\r\nOnce the page is reloaded, DevTools will automatically reconnect.\r\n```\r\n![electron-crash](https://cloud.githubusercontent.com/assets/6275952/19868446/58daa254-9fa8-11e6-9491-4479402e24e1.PNG)\r\n\r\nHowever, if I define the `console` object in the context thus:\r\n```TypeScript\r\nconsole: {\r\n  log: (...args) => console.log(...args),\r\n },\r\n```\r\n\r\nthen the script works fine and DevTools does not disconnect, which seems strange, since I have seen many examples online where the `console` object is defined as in the first example.\r\n\r\n\r\n"}}
{"actor":{"display_login":"michaelbromley"}}