fix: errors in evaluate should be JavaScriptErrorInEvaluate (#28706)

Fixes https://github.com/microsoft/playwright/issues/28690
This commit is contained in:
Yury Semikhatsky 2023-12-19 10:47:43 -08:00 committed by GitHub
parent b33a04bc88
commit afc1ac7063
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 2 deletions

View File

@ -272,7 +272,7 @@ export async function evaluateExpression(context: ExecutionContext, expression:
if (!handle._objectId)
return { fallThrough: handle._value };
if (handle._disposed)
throw new Error('JSHandle is disposed!');
throw new JavaScriptErrorInEvaluate('JSHandle is disposed!');
const adopted = context.adoptIfNeeded(handle);
if (adopted === null)
return { h: pushHandle(Promise.resolve(handle)) };
@ -285,7 +285,7 @@ export async function evaluateExpression(context: ExecutionContext, expression:
const utilityScriptObjectIds: ObjectId[] = [];
for (const handle of await Promise.all(handles)) {
if (handle._context !== context)
throw new Error('JSHandles can be evaluated only in the context they were created!');
throw new JavaScriptErrorInEvaluate('JSHandles can be evaluated only in the context they were created!');
utilityScriptObjectIds.push(handle._objectId!);
}

View File

@ -215,3 +215,17 @@ it('should dispatch device motion event', async ({ page, server, isAndroid }) =>
expect(await page.evaluate('rotationRate.gamma')).toBe(15);
expect(await page.evaluate('interval')).toBe(16);
});
it('should throw if argument is from different frame', async ({ page, server }) => {
it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/28690' });
await page.goto(server.PREFIX + '/frames/one-frame.html');
{
const dataTransfer = await page.frames()[1].evaluateHandle(() => new DataTransfer());
await page.frameLocator('iframe').locator('div').dispatchEvent('drop', { dataTransfer });
}
{
const dataTransfer = await page.evaluateHandle(() => new DataTransfer());
await expect(page.frameLocator('iframe').locator('div').dispatchEvent('drop', { dataTransfer }))
.rejects.toThrow('JSHandles can be evaluated only in the context they were created!');
}
});