-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
[Feature] Expose JSHandle _remoteObject #2275
Comments
The simplest way to proxy is: page.on('console', console.log); If you'd like to process arguments, you can use |
I did try If anyone else hits this same problem, this is something that sort of works. let msgType = msg.type();
msgType = msgType === `warning` ? `warn` : msgType; // so we can feed it to console.warn
const msgText = msg.text();
const args = msg.args().map((jsHandle) => {
// see https://github.com/microsoft/playwright/issues/2275
const remoteObject = jsHandle[`_remoteObject`];
if (Object.prototype.hasOwnProperty.call(remoteObject, `value`)) {
return remoteObject.value;
} else if (remoteObject.type === `object` && remoteObject.subtype === `error` && remoteObject.description) {
const errStack = remoteObject.description;
const errMessage = errStack.split(`\n`)[0];
const err = new Error(errMessage);
err.stack = errStack;
return err;
}
// we don't know how to parse this out yet, return as is
return remoteObject;
});
// proxy browser console stream
console[msgType](...args); It turns out, getting error messages out of console in a uniform way from firefox, chromium, webkit is quite tricky. I'll bash my head more against this to dig even deeper but ideal experience I'm looking for is rich console proxying. @pavelfeldman , just want to say, I'm very grateful for your contributions to chrome-devtools -> puppeteer -> playwright. Thanks for building amazing things. Really loving playwright. |
Hang on, trying to understand your scenario. We definitely don't want it to be that complicated to process errors. Is it something like below? console.log(new Error("error message")); If that is the case, we definitely want to make const {message, stack} = await arg.evaluate(error => ({
message: error.message,
stack: error.stack
})); What happens above is we take a handle to an error message and evaluate on it, cherry picking two property values that we return as values, not as a handle. |
Closing as fixed in #2329 |
When I debug the the console messages passed via
All I see is a bunch of JSHandles, I tried to figure out if I can get a usable value out of it, like strings, numbers, or proper Error objects with intact stack traces, but I couldn't
I just want to proxy the console error messages from browser to node process
how do I do this ?
EDIT:
await the jsonValue() helps but I still don't get errors
Do you have plans to expose
_remoteObject
? Seems like we could write a simple function that could return JS like objects for errors types.The text was updated successfully, but these errors were encountered: