diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 0cfc07e65a16..52f4dc71506b 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -480,7 +480,7 @@ bool WebContents::DidAddMessageToConsole(content::WebContents* source, const base::string16& message, int32_t line_no, const base::string16& source_id) { - if (type_ == BROWSER_WINDOW || type_ == OFF_SCREEN) { + if (type_ == OFF_SCREEN) { return false; } else { Emit("console-message", level, message, line_no, source_id); diff --git a/docs/api/web-contents.md b/docs/api/web-contents.md index 07ccefeff8ec..9b56820d0494 100644 --- a/docs/api/web-contents.md +++ b/docs/api/web-contents.md @@ -591,6 +591,18 @@ Returns: Emitted when a `` has been attached to this web contents. +#### Event: 'console-message' + +Returns: + +* `level` Integer +* `message` String +* `line` Integer +* `sourceId` String + +Emitted when the associated window logs a console message. Will not be emitted +for windows with *offscreen rendering* enabled. + ### Instance Methods #### `contents.loadURL(url[, options])` diff --git a/spec/api-web-contents-spec.js b/spec/api-web-contents-spec.js index f4093dd43a49..39e466d56bce 100644 --- a/spec/api-web-contents-spec.js +++ b/spec/api-web-contents-spec.js @@ -667,4 +667,16 @@ describe('webContents module', () => { w.loadURL(`file://${path.join(__dirname, 'fixtures', 'pages', 'theme-color.html')}`) }) }) + + describe('console-message event', () => { + it('is triggered with correct log message', (done) => { + w.webContents.on('console-message', (e, level, message) => { + // Don't just assert as Chromium might emit other logs that we should ignore. + if (message === 'a') { + done() + } + }) + w.loadURL(`file://${fixtures}/pages/a.html`) + }) + }) })