mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
fix: eval serialization w/ overridden URL/RegExp/Date (#21112)
Fixes #21109
This commit is contained in:
parent
000583e048
commit
d6dae8ea1f
@ -35,15 +35,27 @@ type VisitorInfo = {
|
||||
export function source() {
|
||||
|
||||
function isRegExp(obj: any): obj is RegExp {
|
||||
return obj instanceof RegExp || Object.prototype.toString.call(obj) === '[object RegExp]';
|
||||
try {
|
||||
return obj instanceof RegExp || Object.prototype.toString.call(obj) === '[object RegExp]';
|
||||
} catch (error) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function isDate(obj: any): obj is Date {
|
||||
return obj instanceof Date || Object.prototype.toString.call(obj) === '[object Date]';
|
||||
try {
|
||||
return obj instanceof Date || Object.prototype.toString.call(obj) === '[object Date]';
|
||||
} catch (error) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function isURL(obj: any): obj is URL {
|
||||
return obj instanceof URL || Object.prototype.toString.call(obj) === '[object URL]';
|
||||
try {
|
||||
return obj instanceof URL || Object.prototype.toString.call(obj) === '[object URL]';
|
||||
} catch (error) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function isError(obj: any): obj is Error {
|
||||
|
||||
@ -703,6 +703,25 @@ it('should work with overridden globalThis.Window/Document/Node', async ({ page,
|
||||
}
|
||||
});
|
||||
|
||||
it('should work with overridden URL/Date/RegExp', async ({ page, server }) => {
|
||||
const testCases = [
|
||||
// @ts-ignore
|
||||
() => globalThis.URL = 'foo',
|
||||
// @ts-ignore
|
||||
() => globalThis.RegExp = 'foo',
|
||||
// @ts-ignore
|
||||
() => globalThis.Date = 'foo',
|
||||
];
|
||||
for (const testCase of testCases) {
|
||||
await it.step(testCase.toString(), async () => {
|
||||
await page.goto(server.EMPTY_PAGE);
|
||||
await page.evaluate(testCase);
|
||||
expect(await page.evaluate('1+2')).toBe(3);
|
||||
expect(await page.evaluate(() => ({ 'a': 2023 }))).toEqual({ 'a': 2023 });
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
it('should expose utilityScript', async ({ page }) => {
|
||||
const result = await (page.mainFrame() as any)._evaluateExposeUtilityScript((utilityScript, { a }) => {
|
||||
return { utils: 'parseEvaluationResultValue' in utilityScript, a };
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user