diff --git a/package-lock.json b/package-lock.json index 79eb26b429..ead22e096d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -23,7 +23,7 @@ "@babel/preset-react": "^7.18.6", "@types/codemirror": "^5.60.5", "@types/formidable": "^2.0.4", - "@types/node": "=14.18.24", + "@types/node": "=14.18.34", "@types/react": "^18.0.12", "@types/react-dom": "^18.0.5", "@types/resize-observer-browser": "^0.1.7", @@ -59,7 +59,7 @@ "rimraf": "^3.0.2", "socksv5": "0.0.6", "ssim.js": "^3.5.0", - "typescript": "^4.7.3", + "typescript": "^4.9.3", "vite": "^3.2.1", "ws": "^8.5.0", "xml2js": "^0.4.23", @@ -1083,8 +1083,9 @@ "license": "MIT" }, "node_modules/@types/node": { - "version": "14.18.24", - "license": "MIT" + "version": "14.18.34", + "resolved": "https://registry.npmjs.org/@types/node/-/node-14.18.34.tgz", + "integrity": "sha512-hcU9AIQVHmPnmjRK+XUUYlILlr9pQrsqSrwov/JK1pnf3GTQowVBhx54FbvM0AU/VXGH4i3+vgXS5EguR7fysA==" }, "node_modules/@types/normalize-package-data": { "version": "2.4.1", @@ -2348,9 +2349,10 @@ "integrity": "sha512-M8WEXFuKXMYMVr45fo8mq0wUrrJHheiKZf6BArTKk9ZBYCKJEOU5H8cdWgDT+qCVZf7Na4lVUaZsA+h6uA9+PA==" }, "node_modules/electron/node_modules/@types/node": { - "version": "16.11.47", - "dev": true, - "license": "MIT" + "version": "16.18.6", + "resolved": "https://registry.npmjs.org/@types/node/-/node-16.18.6.tgz", + "integrity": "sha512-vmYJF0REqDyyU0gviezF/KHq/fYaUbFhkcNbQCuPGFQj6VTbXuHZoxs/Y7mutWe73C8AC6l9fFu8mSYiBAqkGA==", + "dev": true }, "node_modules/electron/node_modules/debug": { "version": "2.6.9", @@ -5081,9 +5083,10 @@ "license": "MIT" }, "node_modules/typescript": { - "version": "4.7.3", + "version": "4.9.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.3.tgz", + "integrity": "sha512-CIfGzTelbKNEnLpLdGFgdyKhG23CKdKgQPOBc+OUNrkJ2vr+KSzsSV5kq5iWhEQbok+quxgGzrAtGWCyU7tHnA==", "dev": true, - "license": "Apache-2.0", "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" @@ -6778,7 +6781,9 @@ "dev": true }, "@types/node": { - "version": "14.18.24" + "version": "14.18.34", + "resolved": "https://registry.npmjs.org/@types/node/-/node-14.18.34.tgz", + "integrity": "sha512-hcU9AIQVHmPnmjRK+XUUYlILlr9pQrsqSrwov/JK1pnf3GTQowVBhx54FbvM0AU/VXGH4i3+vgXS5EguR7fysA==" }, "@types/normalize-package-data": { "version": "2.4.1", @@ -7600,7 +7605,9 @@ }, "dependencies": { "@types/node": { - "version": "16.11.47", + "version": "16.18.6", + "resolved": "https://registry.npmjs.org/@types/node/-/node-16.18.6.tgz", + "integrity": "sha512-vmYJF0REqDyyU0gviezF/KHq/fYaUbFhkcNbQCuPGFQj6VTbXuHZoxs/Y7mutWe73C8AC6l9fFu8mSYiBAqkGA==", "dev": true }, "debug": { @@ -9304,7 +9311,9 @@ "dev": true }, "typescript": { - "version": "4.7.3", + "version": "4.9.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.3.tgz", + "integrity": "sha512-CIfGzTelbKNEnLpLdGFgdyKhG23CKdKgQPOBc+OUNrkJ2vr+KSzsSV5kq5iWhEQbok+quxgGzrAtGWCyU7tHnA==", "dev": true }, "universalify": { diff --git a/package.json b/package.json index 4493da9084..636113e8d3 100644 --- a/package.json +++ b/package.json @@ -58,7 +58,7 @@ "@babel/preset-react": "^7.18.6", "@types/codemirror": "^5.60.5", "@types/formidable": "^2.0.4", - "@types/node": "=14.18.24", + "@types/node": "=14.18.34", "@types/react": "^18.0.12", "@types/react-dom": "^18.0.5", "@types/resize-observer-browser": "^0.1.7", @@ -94,7 +94,7 @@ "rimraf": "^3.0.2", "socksv5": "0.0.6", "ssim.js": "^3.5.0", - "typescript": "^4.7.3", + "typescript": "^4.9.3", "vite": "^3.2.1", "ws": "^8.5.0", "xml2js": "^0.4.23", diff --git a/packages/playwright-core/src/server/dom.ts b/packages/playwright-core/src/server/dom.ts index 749c14c08b..d8a3896b34 100644 --- a/packages/playwright-core/src/server/dom.ts +++ b/packages/playwright-core/src/server/dom.ts @@ -120,6 +120,7 @@ export class FrameExecutionContext extends js.ExecutionContext { } export class ElementHandle extends js.JSHandle { + __elementhandle: T = true as any; declare readonly _context: FrameExecutionContext; readonly _page: Page; declare readonly _objectId: string; diff --git a/packages/playwright-core/src/server/javascript.ts b/packages/playwright-core/src/server/javascript.ts index 46af3c5b93..bec7106f3a 100644 --- a/packages/playwright-core/src/server/javascript.ts +++ b/packages/playwright-core/src/server/javascript.ts @@ -27,10 +27,16 @@ export type RemoteObject = { value?: any }; -type NoHandles = Arg extends JSHandle ? never : (Arg extends object ? { [Key in keyof Arg]: NoHandles } : Arg); +interface TaggedAsJSHandle { + __jshandle: T; +} +interface TaggedAsElementHandle { + __elementhandle: T; +} +type NoHandles = Arg extends TaggedAsJSHandle ? never : (Arg extends object ? { [Key in keyof Arg]: NoHandles } : Arg); type Unboxed = - Arg extends dom.ElementHandle ? T : - Arg extends JSHandle ? T : + Arg extends TaggedAsElementHandle ? T : + Arg extends TaggedAsJSHandle ? T : Arg extends NoHandles ? Arg : Arg extends [infer A0] ? [Unboxed] : Arg extends [infer A0, infer A1] ? [Unboxed, Unboxed] : @@ -129,6 +135,7 @@ export class ExecutionContext extends SdkObject { } export class JSHandle extends SdkObject { + __jshandle: T = true as any; readonly _context: ExecutionContext; _disposed = false; readonly _objectId: ObjectId | undefined; diff --git a/tests/config/queryObjects.ts b/tests/config/queryObjects.ts index f2e3c49546..1513e0b8d3 100644 --- a/tests/config/queryObjects.ts +++ b/tests/config/queryObjects.ts @@ -29,7 +29,7 @@ export async function queryObjectCount(type: Function): Promise { prototypeObjectId: constructorFunction.objectId }, (_, result) => f(result))) as any; - const { result: { value } } = await new Promise(f => session.post('Runtime.callFunctionOn', { + const { result: { value } } = await new Promise(f => session.post('Runtime.callFunctionOn', { functionDeclaration: 'function (arr) { return this.length; }', objectId: instanceArray.objectId, arguments: [{ objectId: instanceArray.objectId }], diff --git a/tests/page/page-keyboard.spec.ts b/tests/page/page-keyboard.spec.ts index 3338fdfeb3..388c68539b 100644 --- a/tests/page/page-keyboard.spec.ts +++ b/tests/page/page-keyboard.spec.ts @@ -657,8 +657,7 @@ async function captureLastKeydown(page) { lastEvent.key = e.key; lastEvent.code = e.code; lastEvent.metaKey = e.metaKey; - // keyIdentifier only exists in WebKit, and isn't in TypeScript's lib. - lastEvent.keyIdentifier = 'keyIdentifier' in e && e['keyIdentifier']; + lastEvent.keyIdentifier = 'keyIdentifier' in e && typeof e['keyIdentifier'] === 'string' && e['keyIdentifier']; }, true); return lastEvent; }); diff --git a/utils/generate_types/test/test.ts b/utils/generate_types/test/test.ts index ac608c1165..e9a3a9d4ba 100644 --- a/utils/generate_types/test/test.ts +++ b/utils/generate_types/test/test.ts @@ -567,6 +567,23 @@ playwright.chromium.launch().then(async browser => { const value = await handle.jsonValue(); const assertion: AssertType = true; } + { + const handle = await page.evaluateHandle(() => document.body); + const tuple = { s: '', n: 23, h: handle }; + const value = await page.evaluate(([{ s, n, h }]) => { + return parseInt(s) + n + parseInt(h.nodeName); + }, [tuple]); + const assertion: AssertType = true; + } + { + type T = ({ s: string } | playwright.ElementHandle)[]; + const handle = await page.evaluateHandle(() => document.body); + const tuple: T = [{ s: '' }, handle]; + const value = await page.evaluate(([a, b]) => { + return (a instanceof Node ? a.nodeName : a.s) + (b instanceof Node ? b.nodeName : b.s); + }, tuple); + const assertion: AssertType = true; + } { const handle = await page.evaluateHandle(() => document.createElement('body')); @@ -861,3 +878,4 @@ import { Geolocation, HTTPCredentials, } from 'playwright'; +