Skip to content

Commit

Permalink
Fix (web-crawler): Use jsonValue() method to get the serialized arg…
Browse files Browse the repository at this point in the history
…uments instead of calling `evaluate()` method, which may cause unhandled rejection due to destroyed context.
  • Loading branch information
psmyrek committed Sep 24, 2024
1 parent 15a8f79 commit c89444e
Showing 1 changed file with 1 addition and 19 deletions.
20 changes: 1 addition & 19 deletions packages/ckeditor5-dev-web-crawler/lib/runcrawler.js
Original file line number Diff line number Diff line change
Expand Up @@ -561,25 +561,7 @@ function registerErrorHandlers( page, { link, onError } ) {
return;
}

const serializeArgumentInPageContext = argument => {
// Since errors are not serializable, return the message with the call stack as the output text.
if ( argument instanceof Error ) {
return argument.stack;
}

// Cast non-string iterable argument to an array.
if ( typeof argument !== 'string' && argument[ Symbol.iterator ] ) {
return [ ...argument ];
}

// Return argument right away. Since we use `executionContext().evaluate()`, it'll return JSON value of the
// argument if possible, or `undefined` if it fails to stringify it.
return argument;
};

const serializeArguments = argument => {
return argument.evaluate( serializeArgumentInPageContext, argument );
};
const serializeArguments = argument => argument.jsonValue();

const serializedArguments = await Promise.all( message.args().map( serializeArguments ) );

Expand Down

0 comments on commit c89444e

Please sign in to comment.