fix: handle failures of adoptElementHandle

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-04 13:23:09 -08:00
parent 25af050bd4
commit 8963e8f049
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> {
const {object} = await this._client.send('DOM.resolveNode', {
const result = await this._client.send('DOM.resolveNode', {
backendNodeId,
executionContextId: (to.context._delegate as ExecutionContextDelegate)._contextId,
});
return to.context._createHandle(object).asElement()!;
}).catch(debugError);
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);
}
export function waitForSelectorTask(selector: string | ScopedSelector, timeout: number): Task {
export function waitForSelectorTask(selector: string | types.Selector, timeout: number): Task {
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);
return domWorld.context.evaluateHandle((injected: Injected, selector: string, scope: SelectorRoot | undefined, visible: boolean | undefined, timeout: number) => {
if (visible !== undefined)