fix: handle failures of adoptElementHandle (#134)

There is no way to trigger this issue through the api just yet, but there will be
once we support handles as selectors.
This commit is contained in:
Dmitry Gozman 2019-12-05 08:45:36 -08:00 committed by Yury Semikhatsky
parent 25af050bd4
commit 3f554b3273
2 changed files with 6 additions and 5 deletions

View file

@ -202,11 +202,13 @@ export class DOMWorldDelegate implements dom.DOMWorldDelegate {
} }
async adoptBackendNodeId(backendNodeId: Protocol.DOM.BackendNodeId, to: dom.DOMWorld): Promise<dom.ElementHandle> { async adoptBackendNodeId(backendNodeId: Protocol.DOM.BackendNodeId, to: dom.DOMWorld): Promise<dom.ElementHandle> {
const {object} = await this._client.send('DOM.resolveNode', { const result = await this._client.send('DOM.resolveNode', {
backendNodeId, backendNodeId,
executionContextId: (to.context._delegate as ExecutionContextDelegate)._contextId, executionContextId: (to.context._delegate as ExecutionContextDelegate)._contextId,
}); }).catch(debugError);
return to.context._createHandle(object).asElement()!; if (!result)
throw new Error('Unable to adopt element handle from a different document');
return to.context._createHandle(result.object).asElement()!;
} }
} }

View file

@ -344,9 +344,8 @@ export function waitForFunctionTask(pageFunction: Function | string, options: ty
}, await domWorld.injected(), predicateBody, polling, options.timeout, ...args); }, await domWorld.injected(), predicateBody, polling, options.timeout, ...args);
} }
export function waitForSelectorTask(selector: string | ScopedSelector, timeout: number): Task { export function waitForSelectorTask(selector: string | types.Selector, timeout: number): Task {
return async (domWorld: DOMWorld) => { return async (domWorld: DOMWorld) => {
// TODO: we should not be able to adopt selector scope from a different document - handle this case.
const resolved = await domWorld.resolveSelector(selector); const resolved = await domWorld.resolveSelector(selector);
return domWorld.context.evaluateHandle((injected: Injected, selector: string, scope: SelectorRoot | undefined, visible: boolean | undefined, timeout: number) => { return domWorld.context.evaluateHandle((injected: Injected, selector: string, scope: SelectorRoot | undefined, visible: boolean | undefined, timeout: number) => {
if (visible !== undefined) if (visible !== undefined)