Skip to content
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

Send error doesn't have full stack trace #570

Open
yotamN opened this issue Jan 7, 2025 · 2 comments
Open

Send error doesn't have full stack trace #570

yotamN opened this issue Jan 7, 2025 · 2 comments

Comments

@yotamN
Copy link

yotamN commented Jan 7, 2025

Description

When an error is being raised in the send method, the stack trace doesn't help since it's inside a callback.

Example

I'm not sure how to make an error explicitly but any error in there will have a stack trace without the calling code.

@cyrus-and
Copy link
Owner

Can you show me a use case, an example stack trace, and what you would expect instead?

@yotamN
Copy link
Author

yotamN commented Jan 21, 2025

Sorry for the delay. Here is an example, modified from the example in the README:

example.js
const CDP = require('chrome-remote-interface');

async function example() {
    let client;
    try {
	// connect to endpoint
	client = await CDP();

	const { targetId } = await client.send('Target.createTarget', {
	    url: 'about:blank',
	});
	const { sessionId } = await client.send('Target.attachToTarget', {
	    targetId,
	    flatten: true,
	});

	await client.send('Page.setFontFamilies', { fontFamilies: 'abc' }, sessionId);
    } catch (err) {
	console.error(err);
    } finally {
	if (client) {
	    await client.close();
	}
    }
}

example();

As you can see, I've sent a malformed value to Page.setFontFamilies, resulting in an error from the server. The error provides a traceback, but it doesn't indicate where the event was sent from. Here is what I see:

traceback
ProtocolError: Invalid parameters (Failed to deserialize params.fontFamilies - CBOR: map start expected at position 21)
    at /tmp/tmp.MnSBByXgtf/node_modules/chrome-remote-interface/lib/chrome.js:94:35
    at Chrome._handleMessage (/tmp/tmp.MnSBByXgtf/node_modules/chrome-remote-interface/lib/chrome.js:272:17)
    at WebSocket.<anonymous> (/tmp/tmp.MnSBByXgtf/node_modules/chrome-remote-interface/lib/chrome.js:240:22)
    at WebSocket.emit (node:events:518:28)
    at Receiver.receiverOnMessage (/tmp/tmp.MnSBByXgtf/node_modules/ws/lib/websocket.js:1070:20)
    at Receiver.emit (node:events:518:28)
    at Receiver.dataMessage (/tmp/tmp.MnSBByXgtf/node_modules/ws/lib/receiver.js:517:14)
    at Receiver.getData (/tmp/tmp.MnSBByXgtf/node_modules/ws/lib/receiver.js:435:17)
    at Receiver.startLoop (/tmp/tmp.MnSBByXgtf/node_modules/ws/lib/receiver.js:143:22)
    at Receiver._write (/tmp/tmp.MnSBByXgtf/node_modules/ws/lib/receiver.js:78:10) {
  request: {
    method: 'Page.setFontFamilies',
    params: { fontFamilies: 'abc' },
    sessionId: '954ADA77AA8ED4B9159ED4A896D92EC8'
  },
  response: {
    code: -32602,
    message: 'Invalid parameters',
    data: 'Failed to deserialize params.fontFamilies - CBOR: map start expected at position 21'
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants