mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
chore: don't use Object.freeze for internal properties (#10945)
This commit is contained in:
parent
3fc8da9955
commit
ce5461d0d5
@ -104,7 +104,7 @@ export class BidiPage extends Page {
|
|||||||
],
|
],
|
||||||
['browsingContext.userPromptOpened', this.#onDialog.bind(this)],
|
['browsingContext.userPromptOpened', this.#onDialog.bind(this)],
|
||||||
]);
|
]);
|
||||||
#networkManagerEvents = Object.freeze([
|
readonly #networkManagerEvents = [
|
||||||
[
|
[
|
||||||
NetworkManagerEvent.Request,
|
NetworkManagerEvent.Request,
|
||||||
(request: BidiHTTPRequest) => {
|
(request: BidiHTTPRequest) => {
|
||||||
@ -135,9 +135,9 @@ export class BidiPage extends Page {
|
|||||||
this.emit(PageEvent.Response, response);
|
this.emit(PageEvent.Response, response);
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
] as const);
|
] as const;
|
||||||
|
|
||||||
#browsingContextEvents = new Map<symbol, Handler<any>>([
|
readonly #browsingContextEvents = new Map<symbol, Handler<any>>([
|
||||||
[BrowsingContextEvent.Created, this.#onContextCreated.bind(this)],
|
[BrowsingContextEvent.Created, this.#onContextCreated.bind(this)],
|
||||||
[BrowsingContextEvent.Destroyed, this.#onContextDestroyed.bind(this)],
|
[BrowsingContextEvent.Destroyed, this.#onContextDestroyed.bind(this)],
|
||||||
]);
|
]);
|
||||||
|
@ -44,11 +44,10 @@ interface ARIASelector {
|
|||||||
role?: string;
|
role?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const KNOWN_ATTRIBUTES = Object.freeze(['name', 'role']);
|
|
||||||
const isKnownAttribute = (
|
const isKnownAttribute = (
|
||||||
attribute: string
|
attribute: string
|
||||||
): attribute is keyof ARIASelector => {
|
): attribute is keyof ARIASelector => {
|
||||||
return KNOWN_ATTRIBUTES.includes(attribute);
|
return ['name', 'role'].includes(attribute);
|
||||||
};
|
};
|
||||||
|
|
||||||
const normalizeValue = (value: string): string => {
|
const normalizeValue = (value: string): string => {
|
||||||
|
@ -113,7 +113,7 @@ export class NetworkManager extends EventEmitter<CdpNetworkManagerEvents> {
|
|||||||
#userAgent?: string;
|
#userAgent?: string;
|
||||||
#userAgentMetadata?: Protocol.Emulation.UserAgentMetadata;
|
#userAgentMetadata?: Protocol.Emulation.UserAgentMetadata;
|
||||||
|
|
||||||
#handlers = Object.freeze([
|
readonly #handlers = [
|
||||||
['Fetch.requestPaused', this.#onRequestPaused],
|
['Fetch.requestPaused', this.#onRequestPaused],
|
||||||
['Fetch.authRequired', this.#onAuthRequired],
|
['Fetch.authRequired', this.#onAuthRequired],
|
||||||
['Network.requestWillBeSent', this.#onRequestWillBeSent],
|
['Network.requestWillBeSent', this.#onRequestWillBeSent],
|
||||||
@ -123,7 +123,7 @@ export class NetworkManager extends EventEmitter<CdpNetworkManagerEvents> {
|
|||||||
['Network.loadingFailed', this.#onLoadingFailed],
|
['Network.loadingFailed', this.#onLoadingFailed],
|
||||||
['Network.responseReceivedExtraInfo', this.#onResponseReceivedExtraInfo],
|
['Network.responseReceivedExtraInfo', this.#onResponseReceivedExtraInfo],
|
||||||
[CDPSessionEvent.Disconnected, this.#removeClient],
|
[CDPSessionEvent.Disconnected, this.#removeClient],
|
||||||
] as const);
|
] as const;
|
||||||
|
|
||||||
#clients = new Map<CDPSession, DisposableStack>();
|
#clients = new Map<CDPSession, DisposableStack>();
|
||||||
|
|
||||||
|
@ -143,7 +143,7 @@ export class CdpPage extends Page {
|
|||||||
#serviceWorkerBypassed = false;
|
#serviceWorkerBypassed = false;
|
||||||
#userDragInterceptionEnabled = false;
|
#userDragInterceptionEnabled = false;
|
||||||
|
|
||||||
#frameManagerHandlers = Object.freeze([
|
readonly #frameManagerHandlers = [
|
||||||
[
|
[
|
||||||
FrameManagerEvent.FrameAttached,
|
FrameManagerEvent.FrameAttached,
|
||||||
(frame: CdpFrame) => {
|
(frame: CdpFrame) => {
|
||||||
@ -162,9 +162,9 @@ export class CdpPage extends Page {
|
|||||||
this.emit(PageEvent.FrameNavigated, frame);
|
this.emit(PageEvent.FrameNavigated, frame);
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
] as const);
|
] as const;
|
||||||
|
|
||||||
#networkManagerHandlers = Object.freeze([
|
readonly #networkManagerHandlers = [
|
||||||
[
|
[
|
||||||
NetworkManagerEvent.Request,
|
NetworkManagerEvent.Request,
|
||||||
(request: HTTPRequest) => {
|
(request: HTTPRequest) => {
|
||||||
@ -195,9 +195,9 @@ export class CdpPage extends Page {
|
|||||||
this.emit(PageEvent.RequestFinished, request);
|
this.emit(PageEvent.RequestFinished, request);
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
] as const);
|
] as const;
|
||||||
|
|
||||||
#sessionHandlers = Object.freeze([
|
readonly #sessionHandlers = [
|
||||||
[
|
[
|
||||||
CDPSessionEvent.Disconnected,
|
CDPSessionEvent.Disconnected,
|
||||||
() => {
|
() => {
|
||||||
@ -226,7 +226,7 @@ export class CdpPage extends Page {
|
|||||||
['Performance.metrics', this.#emitMetrics.bind(this)],
|
['Performance.metrics', this.#emitMetrics.bind(this)],
|
||||||
['Log.entryAdded', this.#onLogEntryAdded.bind(this)],
|
['Log.entryAdded', this.#onLogEntryAdded.bind(this)],
|
||||||
['Page.fileChooserOpened', this.#onFileChooser.bind(this)],
|
['Page.fileChooserOpened', this.#onFileChooser.bind(this)],
|
||||||
] as const);
|
] as const;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
client: CDPSession,
|
client: CDPSession,
|
||||||
|
@ -23,15 +23,12 @@ import type {QueryHandler} from './QueryHandler.js';
|
|||||||
import {TextQueryHandler} from './TextQueryHandler.js';
|
import {TextQueryHandler} from './TextQueryHandler.js';
|
||||||
import {XPathQueryHandler} from './XPathQueryHandler.js';
|
import {XPathQueryHandler} from './XPathQueryHandler.js';
|
||||||
|
|
||||||
/**
|
const BUILTIN_QUERY_HANDLERS = {
|
||||||
* @internal
|
|
||||||
*/
|
|
||||||
export const BUILTIN_QUERY_HANDLERS = Object.freeze({
|
|
||||||
aria: ARIAQueryHandler,
|
aria: ARIAQueryHandler,
|
||||||
pierce: PierceQueryHandler,
|
pierce: PierceQueryHandler,
|
||||||
xpath: XPathQueryHandler,
|
xpath: XPathQueryHandler,
|
||||||
text: TextQueryHandler,
|
text: TextQueryHandler,
|
||||||
});
|
} as const;
|
||||||
|
|
||||||
const QUERY_SEPARATORS = ['=', '/'];
|
const QUERY_SEPARATORS = ['=', '/'];
|
||||||
|
|
||||||
@ -42,7 +39,7 @@ export function getQueryHandlerByName(
|
|||||||
name: string
|
name: string
|
||||||
): typeof QueryHandler | undefined {
|
): typeof QueryHandler | undefined {
|
||||||
if (name in BUILTIN_QUERY_HANDLERS) {
|
if (name in BUILTIN_QUERY_HANDLERS) {
|
||||||
return BUILTIN_QUERY_HANDLERS[name as 'aria'];
|
return BUILTIN_QUERY_HANDLERS[name as keyof typeof BUILTIN_QUERY_HANDLERS];
|
||||||
}
|
}
|
||||||
return customQueryHandlers.get(name);
|
return customQueryHandlers.get(name);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user