UNPKG

puppeteer-core

Version:

A high-level API to control headless Chrome over the DevTools Protocol

71 lines 1.8 kB
/** * @license * Copyright 2023 Google Inc. * SPDX-License-Identifier: Apache-2.0 */ import { JSHandle } from '../api/JSHandle.js'; import { UnsupportedOperation } from '../common/Errors.js'; import { BidiDeserializer } from './Deserializer.js'; /** * @internal */ export class BidiJSHandle extends JSHandle { static from(value, realm) { return new BidiJSHandle(value, realm); } #remoteValue; realm; #disposed = false; constructor(value, realm) { super(); this.#remoteValue = value; this.realm = realm; } get disposed() { return this.#disposed; } async jsonValue() { return await this.evaluate(value => { return value; }); } asElement() { return null; } async dispose() { if (this.#disposed) { return; } this.#disposed = true; await this.realm.destroyHandles([this]); } get isPrimitiveValue() { switch (this.#remoteValue.type) { case 'string': case 'number': case 'bigint': case 'boolean': case 'undefined': case 'null': return true; default: return false; } } toString() { if (this.isPrimitiveValue) { return 'JSHandle:' + BidiDeserializer.deserialize(this.#remoteValue); } return 'JSHandle@' + this.#remoteValue.type; } get id() { return 'handle' in this.#remoteValue ? this.#remoteValue.handle : undefined; } remoteValue() { return this.#remoteValue; } remoteObject() { throw new UnsupportedOperation('Not available in WebDriver BiDi'); } } //# sourceMappingURL=JSHandle.js.map