From 3734cda9b5f4d11ee4e2e254b295466d4ff8e6c9 Mon Sep 17 00:00:00 2001 From: YusukeIwaki Date: Wed, 21 Sep 2022 02:40:06 +0900 Subject: [PATCH] fix!: remove root from WaitForSelectorOptions chore: make execution context frame-independent --- development/DOCS_VERSION | 2 +- development/puppeteer.api.json | 1119 ++++++----------- lib/puppeteer.rb | 2 +- lib/puppeteer/aria_query_handler.rb | 62 +- lib/puppeteer/custom_query_handler.rb | 31 +- lib/puppeteer/element_handle.rb | 25 +- lib/puppeteer/execution_context.rb | 63 +- lib/puppeteer/frame.rb | 34 +- lib/puppeteer/frame_manager.rb | 4 +- .../{dom_world.rb => isolated_world.rb} | 56 +- lib/puppeteer/js_handle.rb | 8 +- lib/puppeteer/page.rb | 3 +- lib/puppeteer/query_handler_manager.rb | 4 +- lib/puppeteer/remote_object.rb | 4 +- spec/integration/frame_spec.rb | 1 - spec/integration/wait_task_spec.rb | 4 +- spec/puppeteer/element_handle_spec.rb | 7 +- 17 files changed, 547 insertions(+), 882 deletions(-) rename lib/puppeteer/{dom_world.rb => isolated_world.rb} (93%) diff --git a/development/DOCS_VERSION b/development/DOCS_VERSION index fd1bd70b..0558d326 100644 --- a/development/DOCS_VERSION +++ b/development/DOCS_VERSION @@ -1 +1 @@ -16.2.0 +17.1.3 diff --git a/development/puppeteer.api.json b/development/puppeteer.api.json index bd4631ec..80e63544 100644 --- a/development/puppeteer.api.json +++ b/development/puppeteer.api.json @@ -3454,7 +3454,7 @@ { "kind": "PropertySignature", "canonicalReference": "puppeteer!ClickOptions#offset:member", - "docComment": "/**\n * Offset for the clickable point relative to the top-left corder of the border box.\n */\n", + "docComment": "/**\n * Offset for the clickable point relative to the top-left corner of the border box.\n */\n", "excerptTokens": [ { "kind": "Content", @@ -5497,7 +5497,7 @@ { "kind": "Method", "canonicalReference": "puppeteer!Coverage#startJSCoverage:member(1)", - "docComment": "/**\n * @remarks\n *\n * Anonymous scripts are ones that don't have an associated url. These are scripts that are dynamically created on the page using `eval` or `new Function`. If `reportAnonymousScripts` is set to `true`, anonymous scripts will have `pptr://__puppeteer_evaluation_script__` as their URL.\n *\n * @param options - Set of configurable options for coverage defaults to `resetOnNavigation : true, reportAnonymousScripts : false`\n *\n * @returns Promise that resolves when coverage is started.\n */\n", + "docComment": "/**\n * @remarks\n *\n * Anonymous scripts are ones that don't have an associated url. These are scripts that are dynamically created on the page using `eval` or `new Function`. If `reportAnonymousScripts` is set to `true`, anonymous scripts URL will start with `debugger://VM` (unless a magic //# sourceURL comment is present, in which case that will the be URL).\n *\n * @param options - Set of configurable options for coverage defaults to `resetOnNavigation : true, reportAnonymousScripts : false`\n *\n * @returns Promise that resolves when coverage is started.\n */\n", "excerptTokens": [ { "kind": "Content", @@ -8199,6 +8199,36 @@ "isOptional": false, "name": "focus" }, + { + "kind": "Property", + "canonicalReference": "puppeteer!ElementHandle#frame:member", + "docComment": "", + "excerptTokens": [ + { + "kind": "Content", + "text": "get frame(): " + }, + { + "kind": "Reference", + "text": "Frame", + "canonicalReference": "puppeteer!Frame:class" + }, + { + "kind": "Content", + "text": ";" + } + ], + "isReadonly": true, + "isOptional": false, + "releaseTag": "Public", + "name": "frame", + "propertyTypeTokenRange": { + "startIndex": 1, + "endIndex": 2 + }, + "isStatic": false, + "isProtected": false + }, { "kind": "Method", "canonicalReference": "puppeteer!ElementHandle#hover:member(1)", @@ -8802,24 +8832,11 @@ "kind": "Content", "text": ", options?: " }, - { - "kind": "Reference", - "text": "Exclude", - "canonicalReference": "!Exclude:type" - }, - { - "kind": "Content", - "text": "<" - }, { "kind": "Reference", "text": "WaitForSelectorOptions", "canonicalReference": "puppeteer!WaitForSelectorOptions:interface" }, - { - "kind": "Content", - "text": ", 'root'>" - }, { "kind": "Content", "text": "): " @@ -8871,8 +8888,8 @@ ], "isStatic": false, "returnTypeTokenRange": { - "startIndex": 10, - "endIndex": 16 + "startIndex": 7, + "endIndex": 13 }, "releaseTag": "Public", "isProtected": false, @@ -8890,7 +8907,7 @@ "parameterName": "options", "parameterTypeTokenRange": { "startIndex": 5, - "endIndex": 9 + "endIndex": 6 }, "isOptional": true } @@ -9611,520 +9628,92 @@ }, { "kind": "Content", - "text": ";" - } - ], - "isStatic": false, - "returnTypeTokenRange": { - "startIndex": 5, - "endIndex": 6 - }, - "releaseTag": "Public", - "isProtected": false, - "overloadIndex": 1, - "parameters": [ - { - "parameterName": "event", - "parameterTypeTokenRange": { - "startIndex": 1, - "endIndex": 2 - }, - "isOptional": false - }, - { - "parameterName": "handler", - "parameterTypeTokenRange": { - "startIndex": 3, - "endIndex": 4 - }, - "isOptional": false - } - ], - "isOptional": false, - "name": "removeListener" - } - ], - "implementsTokenRanges": [ - { - "startIndex": 1, - "endIndex": 2 - } - ] - }, - { - "kind": "TypeAlias", - "canonicalReference": "puppeteer!EventType:type", - "docComment": "/**\n * @public\n */\n", - "excerptTokens": [ - { - "kind": "Content", - "text": "export declare type EventType = " - }, - { - "kind": "Content", - "text": "string | symbol" - }, - { - "kind": "Content", - "text": ";" - } - ], - "releaseTag": "Public", - "name": "EventType", - "typeTokenRange": { - "startIndex": 1, - "endIndex": 2 - } - }, - { - "kind": "Variable", - "canonicalReference": "puppeteer!executablePath:var", - "docComment": "", - "excerptTokens": [ - { - "kind": "Content", - "text": "executablePath: " - }, - { - "kind": "Content", - "text": "(channel?: string | undefined) => string" - } - ], - "isReadonly": true, - "releaseTag": "Public", - "name": "executablePath", - "variableTypeTokenRange": { - "startIndex": 1, - "endIndex": 2 - } - }, - { - "kind": "Class", - "canonicalReference": "puppeteer!ExecutionContext:class", - "docComment": "/**\n * @remarks\n *\n * Besides pages, execution contexts can be found in {@link WebWorker | workers}.\n *\n * The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the `ExecutionContext` class.\n *\n * @deprecated\n *\n * Do not use directly.\n *\n * Represents a context for JavaScript execution.\n *\n * @example\n *\n * A {@link Page} can have several execution contexts:\n *\n * - Each {@link Frame} of a {@link Page | page} has a \"default\" execution context that is always created after frame is attached to DOM. This context is returned by the {@link Frame.executionContext} method. - Each {@link https://developer.chrome.com/extensions | Chrome extensions} creates additional execution contexts to isolate their code.\n */\n", - "excerptTokens": [ - { - "kind": "Content", - "text": "export declare class ExecutionContext " - } - ], - "releaseTag": "Public", - "name": "ExecutionContext", - "preserveMemberOrder": false, - "members": [ - { - "kind": "Method", - "canonicalReference": "puppeteer!ExecutionContext#evaluate:member(1)", - "docComment": "/**\n * Evaluates the given function.\n *\n * @param pageFunction - The function to evaluate.\n *\n * @param args - Additional arguments to pass into the function.\n *\n * @returns The result of evaluating the function. If the result is an object, a vanilla object containing the serializable properties of the result is returned.\n *\n * @example\n * ```ts\n * const executionContext = await page.mainFrame().executionContext();\n * const result = await executionContext.evaluate(() => Promise.resolve(8 * 7))* ;\n * console.log(result); // prints \"56\"\n * ```\n *\n * @example\n *\n * A string can also be passed in instead of a function:\n * ```ts\n * console.log(await executionContext.evaluate('1 + 2')); // prints \"3\"\n * ```\n *\n * @example\n *\n * Handles can also be passed as `args`. They resolve to their referenced object:\n * ```ts\n * const oneHandle = await executionContext.evaluateHandle(() => 1);\n * const twoHandle = await executionContext.evaluateHandle(() => 2);\n * const result = await executionContext.evaluate(\n * (a, b) => a + b,\n * oneHandle,\n * twoHandle\n * );\n * await oneHandle.dispose();\n * await twoHandle.dispose();\n * console.log(result); // prints '3'.\n * ```\n *\n */\n", - "excerptTokens": [ - { - "kind": "Content", - "text": "evaluate" - }, - { - "kind": "Content", - "text": " = " - }, - { - "kind": "Reference", - "text": "EvaluateFunc", - "canonicalReference": "puppeteer!EvaluateFunc:type" - }, - { - "kind": "Content", - "text": "" - }, - { - "kind": "Content", - "text": ">(pageFunction: " - }, - { - "kind": "Content", - "text": "Func | string" - }, - { - "kind": "Content", - "text": ", ...args: " - }, - { - "kind": "Content", - "text": "Params" - }, - { - "kind": "Content", - "text": "): " - }, - { - "kind": "Reference", - "text": "Promise", - "canonicalReference": "!Promise:interface" - }, - { - "kind": "Content", - "text": "<" - }, - { - "kind": "Reference", - "text": "Awaited", - "canonicalReference": "!Awaited:type" - }, - { - "kind": "Content", - "text": "<" - }, - { - "kind": "Reference", - "text": "ReturnType", - "canonicalReference": "!ReturnType:type" - }, - { - "kind": "Content", - "text": ">>" - }, - { - "kind": "Content", - "text": ";" - } - ], - "typeParameters": [ - { - "typeParameterName": "Params", - "constraintTokenRange": { - "startIndex": 1, - "endIndex": 2 - }, - "defaultTypeTokenRange": { - "startIndex": 0, - "endIndex": 0 - } - }, - { - "typeParameterName": "Func", - "constraintTokenRange": { - "startIndex": 3, - "endIndex": 5 - }, - "defaultTypeTokenRange": { - "startIndex": 6, - "endIndex": 8 - } - } - ], - "isStatic": false, - "returnTypeTokenRange": { - "startIndex": 13, - "endIndex": 19 - }, - "releaseTag": "Public", - "isProtected": false, - "overloadIndex": 1, - "parameters": [ - { - "parameterName": "pageFunction", - "parameterTypeTokenRange": { - "startIndex": 9, - "endIndex": 10 - }, - "isOptional": false - }, - { - "parameterName": "args", - "parameterTypeTokenRange": { - "startIndex": 11, - "endIndex": 12 - }, - "isOptional": false - } - ], - "isOptional": false, - "name": "evaluate" - }, - { - "kind": "Method", - "canonicalReference": "puppeteer!ExecutionContext#evaluateHandle:member(1)", - "docComment": "/**\n * Evaluates the given function.\n *\n * Unlike {@link ExecutionContext.evaluate | evaluate}, this method returns a handle to the result of the function.\n *\n * This method may be better suited if the object cannot be serialized (e.g. `Map`) and requires further manipulation.\n *\n * @param pageFunction - The function to evaluate.\n *\n * @param args - Additional arguments to pass into the function.\n *\n * @returns A {@link JSHandle | handle} to the result of evaluating the function. If the result is a `Node`, then this will return an {@link ElementHandle | element handle}.\n *\n * @example\n * ```ts\n * const context = await page.mainFrame().executionContext();\n * const handle: JSHandle = await context.evaluateHandle(\n * () => Promise.resolve(self)\n * );\n * ```\n *\n * @example\n *\n * A string can also be passed in instead of a function.\n * ```ts\n * const handle: JSHandle = await context.evaluateHandle('1 + 2');\n * ```\n *\n * @example\n *\n * Handles can also be passed as `args`. They resolve to their referenced object:\n * ```ts\n * const bodyHandle: ElementHandle =\n * await context.evaluateHandle(() => {\n * return document.body;\n * });\n * const stringHandle: JSHandle = await context.evaluateHandle(\n * body => body.innerHTML,\n * body\n * );\n * console.log(await stringHandle.jsonValue()); // prints body's innerHTML\n * // Always dispose your garbage! :)\n * await bodyHandle.dispose();\n * await stringHandle.dispose();\n * ```\n *\n */\n", - "excerptTokens": [ - { - "kind": "Content", - "text": "evaluateHandle" - }, - { - "kind": "Content", - "text": " = " - }, - { - "kind": "Reference", - "text": "EvaluateFunc", - "canonicalReference": "puppeteer!EvaluateFunc:type" - }, - { - "kind": "Content", - "text": "" - }, - { - "kind": "Content", - "text": ">(pageFunction: " - }, - { - "kind": "Content", - "text": "Func | string" - }, - { - "kind": "Content", - "text": ", ...args: " - }, - { - "kind": "Content", - "text": "Params" - }, - { - "kind": "Content", - "text": "): " - }, - { - "kind": "Reference", - "text": "Promise", - "canonicalReference": "!Promise:interface" - }, - { - "kind": "Content", - "text": "<" - }, - { - "kind": "Reference", - "text": "HandleFor", - "canonicalReference": "puppeteer!HandleFor:type" - }, - { - "kind": "Content", - "text": "<" - }, - { - "kind": "Reference", - "text": "Awaited", - "canonicalReference": "!Awaited:type" - }, - { - "kind": "Content", - "text": "<" - }, - { - "kind": "Reference", - "text": "ReturnType", - "canonicalReference": "!ReturnType:type" - }, - { - "kind": "Content", - "text": ">>>" - }, - { - "kind": "Content", - "text": ";" - } - ], - "typeParameters": [ - { - "typeParameterName": "Params", - "constraintTokenRange": { - "startIndex": 1, - "endIndex": 2 - }, - "defaultTypeTokenRange": { - "startIndex": 0, - "endIndex": 0 - } - }, - { - "typeParameterName": "Func", - "constraintTokenRange": { - "startIndex": 3, - "endIndex": 5 - }, - "defaultTypeTokenRange": { - "startIndex": 6, - "endIndex": 8 - } - } - ], - "isStatic": false, - "returnTypeTokenRange": { - "startIndex": 13, - "endIndex": 21 - }, - "releaseTag": "Public", - "isProtected": false, - "overloadIndex": 1, - "parameters": [ - { - "parameterName": "pageFunction", - "parameterTypeTokenRange": { - "startIndex": 9, - "endIndex": 10 - }, - "isOptional": false - }, - { - "parameterName": "args", - "parameterTypeTokenRange": { - "startIndex": 11, - "endIndex": 12 - }, - "isOptional": false - } - ], - "isOptional": false, - "name": "evaluateHandle" - }, - { - "kind": "Method", - "canonicalReference": "puppeteer!ExecutionContext#frame:member(1)", - "docComment": "/**\n * @remarks\n *\n * Not every execution context is associated with a frame. For example, {@link WebWorker | workers} have execution contexts that are not associated with frames.\n *\n * @returns The frame associated with this execution context.\n */\n", - "excerptTokens": [ - { - "kind": "Content", - "text": "frame(): " - }, - { - "kind": "Reference", - "text": "Frame", - "canonicalReference": "puppeteer!Frame:class" - }, - { - "kind": "Content", - "text": " | null" - }, - { - "kind": "Content", - "text": ";" - } - ], - "isStatic": false, - "returnTypeTokenRange": { - "startIndex": 1, - "endIndex": 3 - }, - "releaseTag": "Public", - "isProtected": false, - "overloadIndex": 1, - "parameters": [], - "isOptional": false, - "name": "frame" - }, - { - "kind": "Method", - "canonicalReference": "puppeteer!ExecutionContext#queryObjects:member(1)", - "docComment": "/**\n * Iterates through the JavaScript heap and finds all the objects with the given prototype.\n *\n * @param prototypeHandle - a handle to the object prototype\n *\n * @returns A handle to an array of objects with the given prototype.\n *\n * @example\n * ```ts\n * // Create a Map object\n * await page.evaluate(() => (window.map = new Map()));\n * // Get a handle to the Map object prototype\n * const mapPrototype = await page.evaluateHandle(() => Map.prototype);\n * // Query all map instances into an array\n * const mapInstances = await page.queryObjects(mapPrototype);\n * // Count amount of map objects in heap\n * const count = await page.evaluate(maps => maps.length, mapInstances);\n * await mapInstances.dispose();\n * await mapPrototype.dispose();\n * ```\n *\n */\n", - "excerptTokens": [ - { - "kind": "Content", - "text": "queryObjects(prototypeHandle: " - }, - { - "kind": "Reference", - "text": "JSHandle", - "canonicalReference": "puppeteer!JSHandle:class" - }, - { - "kind": "Content", - "text": "" - }, - { - "kind": "Content", - "text": "): " - }, - { - "kind": "Reference", - "text": "Promise", - "canonicalReference": "!Promise:interface" - }, - { - "kind": "Content", - "text": "<" - }, - { - "kind": "Reference", - "text": "HandleFor", - "canonicalReference": "puppeteer!HandleFor:type" - }, - { - "kind": "Content", - "text": ">" - }, - { - "kind": "Content", - "text": ";" - } - ], - "typeParameters": [ - { - "typeParameterName": "Prototype", - "constraintTokenRange": { - "startIndex": 0, - "endIndex": 0 - }, - "defaultTypeTokenRange": { - "startIndex": 0, - "endIndex": 0 - } + "text": ";" } ], "isStatic": false, "returnTypeTokenRange": { - "startIndex": 4, - "endIndex": 8 + "startIndex": 5, + "endIndex": 6 }, "releaseTag": "Public", "isProtected": false, "overloadIndex": 1, "parameters": [ { - "parameterName": "prototypeHandle", + "parameterName": "event", "parameterTypeTokenRange": { "startIndex": 1, - "endIndex": 3 + "endIndex": 2 + }, + "isOptional": false + }, + { + "parameterName": "handler", + "parameterTypeTokenRange": { + "startIndex": 3, + "endIndex": 4 }, "isOptional": false } ], "isOptional": false, - "name": "queryObjects" + "name": "removeListener" } ], - "implementsTokenRanges": [] + "implementsTokenRanges": [ + { + "startIndex": 1, + "endIndex": 2 + } + ] + }, + { + "kind": "TypeAlias", + "canonicalReference": "puppeteer!EventType:type", + "docComment": "/**\n * @public\n */\n", + "excerptTokens": [ + { + "kind": "Content", + "text": "export declare type EventType = " + }, + { + "kind": "Content", + "text": "string | symbol" + }, + { + "kind": "Content", + "text": ";" + } + ], + "releaseTag": "Public", + "name": "EventType", + "typeTokenRange": { + "startIndex": 1, + "endIndex": 2 + } + }, + { + "kind": "Variable", + "canonicalReference": "puppeteer!executablePath:var", + "docComment": "", + "excerptTokens": [ + { + "kind": "Content", + "text": "executablePath: " + }, + { + "kind": "Content", + "text": "(channel?: string | undefined) => string" + } + ], + "isReadonly": true, + "releaseTag": "Public", + "name": "executablePath", + "variableTypeTokenRange": { + "startIndex": 1, + "endIndex": 2 + } }, { "kind": "Class", @@ -11019,7 +10608,7 @@ { "kind": "Method", "canonicalReference": "puppeteer!Frame#addScriptTag:member(1)", - "docComment": "/**\n * Adds a `