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

feat(executioncontext): warn on nested js handle #3591

Merged
merged 6 commits into from
Jan 14, 2019
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 17 additions & 9 deletions lib/ExecutionContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,22 @@ class ExecutionContext {
throw new Error('Passed function is not well-serializable!');
}
}

const { exceptionDetails, result: remoteObject } = await this._client.send('Runtime.callFunctionOn', {
functionDeclaration: functionText + '\n' + suffix + '\n',
executionContextId: this._contextId,
arguments: args.map(convertArgument.bind(this)),
returnByValue: false,
awaitPromise: true,
userGesture: true
}).catch(rewriteError);
let funcCallResultP;
try {
funcCallResultP = this._client.send('Runtime.callFunctionOn', {
functionDeclaration: functionText + '\n' + suffix + '\n',
executionContextId: this._contextId,
arguments: args.map(convertArgument.bind(this)),
returnByValue: false,
awaitPromise: true,
userGesture: true
});
} catch (err) {
if (err instanceof TypeError && err.message === 'Converting circular structure to JSON')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this error happens due to convertArgument call. Let's scope it down to this:

try {
  args = args.map(convertArgument.bind(this));
} catch (err) {
  if (err instanceof TypeError && err.message === 'Converting circular structure to JSON')
    err.message += ' Are you passing a nested JSHandle?';
  throw err;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, the error actually happens after convertArgument, in CDPSession.send. It looks like convertArgument prepares the args for serialization, but the call to JSON.stringify is later on.

err.message += ' Are you passing a nested JSHandle?';
throw err;
}
const { exceptionDetails, result: remoteObject } = await funcCallResultP.catch(rewriteError);
if (exceptionDetails)
throw new Error('Evaluation failed: ' + helper.getExceptionMessage(exceptionDetails));
return createJSHandle(this, remoteObject);
Expand Down Expand Up @@ -162,6 +169,7 @@ class ExecutionContext {
throw new Error('Execution context was destroyed, most likely because of a navigation.');
throw error;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: stray line

}

/**
Expand Down