diff --git a/packages/playwright-core/src/server/deviceDescriptors.js b/packages/playwright-core/src/server/deviceDescriptors.ts similarity index 78% rename from packages/playwright-core/src/server/deviceDescriptors.js rename to packages/playwright-core/src/server/deviceDescriptors.ts index 628064098b..b46789c0e5 100644 --- a/packages/playwright-core/src/server/deviceDescriptors.js +++ b/packages/playwright-core/src/server/deviceDescriptors.ts @@ -15,7 +15,8 @@ * limitations under the License. */ -/** - * @type {import('./types').Devices} - */ -module.exports = require("./deviceDescriptorsSource.json") +import type { Devices } from './types'; + +import deviceDescriptorsSource from './deviceDescriptorsSource.json'; + +export const deviceDescriptors = deviceDescriptorsSource as Devices; diff --git a/packages/playwright-core/src/server/dispatchers/localUtilsDispatcher.ts b/packages/playwright-core/src/server/dispatchers/localUtilsDispatcher.ts index 732e135e14..82971d624a 100644 --- a/packages/playwright-core/src/server/dispatchers/localUtilsDispatcher.ts +++ b/packages/playwright-core/src/server/dispatchers/localUtilsDispatcher.ts @@ -26,7 +26,7 @@ import { Dispatcher } from './dispatcher'; import { yazl, yauzl } from '../../zipBundle'; import { ZipFile } from '../../utils/zipFile'; import type * as har from '@trace/har'; -import type { HeadersArray, Devices } from '../types'; +import type { HeadersArray } from '../types'; import { JsonPipeDispatcher } from '../dispatchers/jsonPipeDispatcher'; import { WebSocketTransport } from '../transport'; import { SocksInterceptor } from '../socksInterceptor'; @@ -40,6 +40,7 @@ import type http from 'http'; import type { Playwright } from '../playwright'; import { SdkObject } from '../../server/instrumentation'; import { serializeClientSideCallMetadata } from '../../utils'; +import { deviceDescriptors as descriptors } from '../deviceDescriptors'; export class LocalUtilsDispatcher extends Dispatcher<{ guid: string }, channels.LocalUtilsChannel, RootDispatcher> implements channels.LocalUtilsChannel { _type_LocalUtils: boolean; @@ -53,7 +54,6 @@ export class LocalUtilsDispatcher extends Dispatcher<{ guid: string }, channels. constructor(scope: RootDispatcher, playwright: Playwright) { const localUtils = new SdkObject(playwright, 'localUtils', 'localUtils'); - const descriptors = require('../deviceDescriptors') as Devices; const deviceDescriptors = Object.entries(descriptors) .map(([name, descriptor]) => ({ name, descriptor })); super(scope, localUtils, 'LocalUtils', { diff --git a/packages/playwright-core/src/server/recorder/csharp.ts b/packages/playwright-core/src/server/recorder/csharp.ts index 46fadc244a..461b33e944 100644 --- a/packages/playwright-core/src/server/recorder/csharp.ts +++ b/packages/playwright-core/src/server/recorder/csharp.ts @@ -22,7 +22,7 @@ import type { Action } from './recorderActions'; import type { MouseClickOptions } from './utils'; import { toModifiers } from './utils'; import { escapeWithQuotes } from '../../utils/isomorphic/stringUtils'; -const deviceDescriptors = require('../deviceDescriptorsSource.json'); +import { deviceDescriptors } from '../deviceDescriptors'; import { asLocator } from '../../utils/isomorphic/locatorGenerators'; type CSharpLanguageMode = 'library' | 'mstest' | 'nunit'; diff --git a/packages/playwright-core/src/server/recorder/java.ts b/packages/playwright-core/src/server/recorder/java.ts index d4ebfdeea4..f38b026a37 100644 --- a/packages/playwright-core/src/server/recorder/java.ts +++ b/packages/playwright-core/src/server/recorder/java.ts @@ -21,7 +21,7 @@ import type { ActionInContext } from './codeGenerator'; import type { Action } from './recorderActions'; import type { MouseClickOptions } from './utils'; import { toModifiers } from './utils'; -const deviceDescriptors = require('../deviceDescriptorsSource.json'); +import { deviceDescriptors } from '../deviceDescriptors'; import { JavaScriptFormatter } from './javascript'; import { escapeWithQuotes } from '../../utils/isomorphic/stringUtils'; import { asLocator } from '../../utils/isomorphic/locatorGenerators'; diff --git a/packages/playwright-core/src/server/recorder/javascript.ts b/packages/playwright-core/src/server/recorder/javascript.ts index 548e0f6071..9bafcd6574 100644 --- a/packages/playwright-core/src/server/recorder/javascript.ts +++ b/packages/playwright-core/src/server/recorder/javascript.ts @@ -21,7 +21,7 @@ import type { ActionInContext } from './codeGenerator'; import type { Action } from './recorderActions'; import type { MouseClickOptions } from './utils'; import { toModifiers } from './utils'; -const deviceDescriptors = require('../deviceDescriptorsSource.json'); +import { deviceDescriptors } from '../deviceDescriptors'; import { escapeWithQuotes } from '../../utils/isomorphic/stringUtils'; import { asLocator } from '../../utils/isomorphic/locatorGenerators'; diff --git a/packages/playwright-core/src/server/recorder/python.ts b/packages/playwright-core/src/server/recorder/python.ts index 3be02684bd..ec592840ab 100644 --- a/packages/playwright-core/src/server/recorder/python.ts +++ b/packages/playwright-core/src/server/recorder/python.ts @@ -22,7 +22,7 @@ import type { Action } from './recorderActions'; import type { MouseClickOptions } from './utils'; import { toModifiers } from './utils'; import { escapeWithQuotes, toSnakeCase } from '../../utils/isomorphic/stringUtils'; -const deviceDescriptors = require('../deviceDescriptorsSource.json'); +import { deviceDescriptors } from '../deviceDescriptors'; import { asLocator } from '../../utils/isomorphic/locatorGenerators'; export class PythonLanguageGenerator implements LanguageGenerator { diff --git a/packages/playwright-core/src/server/trace/recorder/snapshotterInjected.ts b/packages/playwright-core/src/server/trace/recorder/snapshotterInjected.ts index 22ece79459..14e34c8aee 100644 --- a/packages/playwright-core/src/server/trace/recorder/snapshotterInjected.ts +++ b/packages/playwright-core/src/server/trace/recorder/snapshotterInjected.ts @@ -540,7 +540,7 @@ export function frameSnapshotStreamer(snapshotStreamer: string, removeNoScript: return checkAndReturn(result); }; - const visitStyleSheet = (sheet: CSSStyleSheet) => { + const visitStyleSheet = (sheet: CSSStyleSheet): { equals: boolean, n: NodeSnapshot } => { const data = ensureCachedData(sheet); const oldCSSText = data.cssText; const cssText = this._updateStyleElementStyleSheetTextIfNeeded(sheet, true /* forceText */)!; diff --git a/packages/trace-viewer/src/snapshotRenderer.ts b/packages/trace-viewer/src/snapshotRenderer.ts index fdcea83288..b98b359f76 100644 --- a/packages/trace-viewer/src/snapshotRenderer.ts +++ b/packages/trace-viewer/src/snapshotRenderer.ts @@ -14,7 +14,15 @@ * limitations under the License. */ -import type { FrameSnapshot, NodeSnapshot, RenderedFrameSnapshot, ResourceSnapshot } from '@trace/snapshot'; +import type { FrameSnapshot, NodeNameAttributesChildNodesSnapshot, NodeSnapshot, RenderedFrameSnapshot, ResourceSnapshot, SubtreeReferenceSnapshot } from '@trace/snapshot'; + +function isNodeNameAttributesChildNodesSnapshot(n: NodeSnapshot): n is NodeNameAttributesChildNodesSnapshot { + return Array.isArray(n) && typeof n[0] === 'string'; +} + +function isSubtreeReferenceSnapshot(n: NodeSnapshot): n is SubtreeReferenceSnapshot { + return Array.isArray(n) && Array.isArray(n[0]); +} export class SnapshotRenderer { private _snapshots: FrameSnapshot[]; @@ -54,7 +62,7 @@ export class SnapshotRenderer { } if (!(n as any)._string) { - if (Array.isArray(n[0])) { + if (isSubtreeReferenceSnapshot(n)) { // Node reference. const referenceIndex = snapshotIndex - n[0][0]; if (referenceIndex >= 0 && referenceIndex <= snapshotIndex) { @@ -63,12 +71,13 @@ export class SnapshotRenderer { if (nodeIndex >= 0 && nodeIndex < nodes.length) (n as any)._string = visit(nodes[nodeIndex], referenceIndex, parentTag, parentAttrs); } - } else if (typeof n[0] === 'string') { + } else if (isNodeNameAttributesChildNodesSnapshot(n)) { + const [name, nodeAttrs, ...children] = n; // Element node. // Note that