You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
this may or may not be an issue, we're using page.exposeFunction() to expose certain APIs to the browser context and from our observations, any error thrown within the APIs turns into an unhandled promise rejection. This is due to the implementation of the .onBindingCalled() handler in Page.
From my observation, exceptions thrown within the _pageBindings function call are not handled in any way and since the .onBindingCalled() function is used as a callback, the resulting rejected promises cannot be handled.
The very minimal reproduction code looks like this:
constpuppeteer=require('puppeteer');puppeteer.launch().then(asyncbrowser=>{constpage=awaitbrowser.newPage();awaitpage.exposeFunction('func',async()=>{thrownewError('err');});awaitpage.evaluate(async()=>{constcontent=awaitwindow.func();});awaitbrowser.close();}).catch(err=>console.log('does not get called'));
The same issue would also manifest in the page.exposeFunction() examples, where a rejection of the readFilePromise would produce an unhandled rejection.
constpuppeteer=require('puppeteer');constfs=require('fs');puppeteer.launch().then(asyncbrowser=>{constpage=awaitbrowser.newPage();page.on('console',msg=>console.log(msg.text()));awaitpage.exposeFunction('readfile',asyncfilePath=>{returnnewPromise((resolve,reject)=>{fs.readFile(filePath,'utf8',(err,text)=>{if(err)reject(err);elseresolve(text);});});});awaitpage.evaluate(async()=>{// use window.readfile to read contents of a fileconstcontent=awaitwindow.readfile('/etc/hosts');console.log(content);});awaitbrowser.close();});
What is the expected result?
I would expect the exceptions thrown from the bound functions to be manageable in some way. Either by allowing a handler to be attached to the page.exposeFunction() call or by backpropagating the errors back to the Browser context so that the Promise there gets rejected with a representation of the exception thrown in Node context.
We implemented those two options manually in our code.
What happens instead?
An unhandled promise rejection is produced.
Thank you for your time.
The text was updated successfully, but these errors were encountered:
mnmkng
changed the title
page.exposeFunction() bindings produce unhandled promise rejections
Functions bound with page.exposeFunction() produce unhandled promise rejections
Nov 15, 2018
Hello everyone,
this may or may not be an issue, we're using
page.exposeFunction()
to expose certain APIs to the browser context and from our observations, any error thrown within the APIs turns into an unhandled promise rejection. This is due to the implementation of the.onBindingCalled()
handler inPage
.See https://github.com/GoogleChrome/puppeteer/blob/c185eeef6119141ebc07f07d46ae0dcb16a555f3/lib/Page.js#L514
From my observation, exceptions thrown within the
_pageBindings
function call are not handled in any way and since the.onBindingCalled()
function is used as a callback, the resulting rejected promises cannot be handled.Is this a bug or intended behavior?
Steps to reproduce
Tell us about your environment:
What steps will reproduce the problem?
The very minimal reproduction code looks like this:
The same issue would also manifest in the
page.exposeFunction()
examples, where a rejection of thereadFile
Promise
would produce an unhandled rejection.What is the expected result?
I would expect the exceptions thrown from the bound functions to be manageable in some way. Either by allowing a handler to be attached to the
page.exposeFunction()
call or by backpropagating the errors back to the Browser context so that thePromise
there gets rejected with a representation of the exception thrown in Node context.We implemented those two options manually in our code.
What happens instead?
An unhandled promise rejection is produced.
Thank you for your time.
The text was updated successfully, but these errors were encountered: