diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 28621b11075..4010d3d5b98 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -1820,6 +1820,8 @@ void WebContents::OnGetZoomLevel(content::RenderFrameHost* rfh, v8::Local WebContents::GetWebPreferences(v8::Isolate* isolate) { WebContentsPreferences* web_preferences = WebContentsPreferences::FromWebContents(web_contents()); + if (!web_preferences) + return v8::Null(isolate); return mate::ConvertToV8(isolate, *web_preferences->web_preferences()); } diff --git a/spec/api-web-contents-spec.js b/spec/api-web-contents-spec.js index 12217029283..cf902522899 100644 --- a/spec/api-web-contents-spec.js +++ b/spec/api-web-contents-spec.js @@ -116,6 +116,16 @@ describe('webContents module', () => { }) }) + describe('getWebPreferences() API', () => { + it('should not crash when called for devTools webContents', (done) => { + w.webContents.openDevTools() + w.webContents.once('devtools-opened', () => { + assert(!w.devToolsWebContents.getWebPreferences()) + done() + }) + }) + }) + describe('before-input-event event', () => { it('can prevent document keyboard events', (done) => { w.loadURL(`file://${path.join(__dirname, 'fixtures', 'pages', 'key-events.html')}`)