puppeteer-core
Version:
A high-level API to control headless Chrome over the DevTools Protocol
87 lines • 2.51 kB
JavaScript
/**
* Copyright 2023 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { JSHandle } from '../api/JSHandle.js';
import { UnsupportedOperation } from '../common/Errors.js';
import { BidiDeserializer } from './Deserializer.js';
import { releaseReference } from './util.js';
/**
* @internal
*/
export class BidiJSHandle extends JSHandle {
#disposed = false;
#sandbox;
#remoteValue;
constructor(sandbox, remoteValue) {
super();
this.#sandbox = sandbox;
this.#remoteValue = remoteValue;
}
context() {
return this.realm.environment.context();
}
get realm() {
return this.#sandbox;
}
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;
if ('handle' in this.#remoteValue) {
await releaseReference(this.context(), this.#remoteValue);
}
}
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