Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
fix(chromium): properly handle CBOR stack limit error (#40947)
Dmitry Gozman0f9632b6efeb
diff --git a/packages/playwright-core/src/server/chromium/crExecutionContext.ts b/packages/playwright-core/src/server/chromium/crExecutionContext.tsindex 11e99ce044..2b2a648ea8 100644--- a/packages/playwright-core/src/server/chromium/crExecutionContext.ts+++ b/packages/playwright-core/src/server/chromium/crExecutionContext.ts@@ -100,7 +100,7 @@ export class CRExecutionContext implements js.ExecutionContextDelegate {}function rewriteError(error: Error): Protocol.Runtime.evaluateReturnValue {- if (error.message.includes('Object reference chain is too long'))+ if (error.message.includes('Object reference chain is too long') || error.message.includes('CBOR: stack limit exceeded'))throw new Error('Cannot serialize result: object reference chain is too long.');if (error.message.includes('Object couldn\'t be returned by value'))return { result: { type: 'undefined' } };diff --git a/tests/page/page-evaluate.spec.ts b/tests/page/page-evaluate.spec.tsindex 4c6e7aaffa..4388b37358 100644--- a/tests/page/page-evaluate.spec.ts+++ b/tests/page/page-evaluate.spec.ts@@ -439,6 +439,18 @@ it('should throw for too deep reference chain', {}, 1000)).rejects.toThrow('Cannot serialize result: object reference chain is too long.');});+it('should throw for too deep reference chain 2', {+ annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/40940' }+}, async ({ page, browserName }) => {+ it.skip(browserName !== 'chromium', 'this is a chromium-only limitation');+ await expect(page.evaluate(depth => {+ let node = {};+ for (let i = 0; i < depth; i++)+ node = { child: node };+ return node;+ }, 200)).rejects.toThrow('Cannot serialize result: object reference chain is too long.');+});+it('should throw usable message for unserializable shallow function', async ({ page }) => {await expect(() => page.evaluate(arg => arg, () => { })).rejects.toThrow(/Attempting to serialize unexpected value: \(\) => {}/);