diff --git a/client/lib/CoreCommandQueue.ts b/client/lib/CoreCommandQueue.ts index 5b91c296d..931476fcb 100644 --- a/client/lib/CoreCommandQueue.ts +++ b/client/lib/CoreCommandQueue.ts @@ -14,6 +14,10 @@ export default class CoreCommandQueue { return this.commandCounter?.lastCommandId; } + public get lastCommand(): CoreCommandQueue['internalState']['lastCommand'] { + return this.internalState.lastCommand; + } + public get nextCommandId(): number { return this.commandCounter?.nextCommandId; } @@ -22,6 +26,10 @@ export default class CoreCommandQueue { queue: Queue; commandsToRecord: ICoreRequestPayload['recordCommands']; interceptFn?: (meta: ISessionMeta, command: string, ...args: any[]) => any; + lastCommand?: Pick< + ICoreRequestPayload, + 'command' | 'commandId' | 'args' | 'callsite' | 'meta' | 'startDate' + >; }; private readonly commandCounter?: ICommandCounter; @@ -110,7 +118,7 @@ export default class CoreCommandQueue { let callsite: string; if (this.mode !== 'production') { - callsite = scriptInstance.getScriptCallSite(); + callsite = JSON.stringify(scriptInstance.getScriptCallSite()); } if (this.internalState.interceptFn) { const result = this.internalState.interceptFn(this.meta, command, ...args); @@ -121,20 +129,29 @@ export default class CoreCommandQueue { return Promise.resolve(result as T); } - const startTime = new Date(); + const startDate = new Date(); const commandId = this.nextCommandId; return this.internalQueue .run(async () => { const recordCommands = [...this.internalState.commandsToRecord]; this.internalState.commandsToRecord.length = 0; + this.internalState.lastCommand = { + meta: this.meta, + command, + args, + startDate, + commandId, + callsite, + }; + this.commandCounter?.emitter.emit('command', command, commandId, args); const response = await this.connection.sendRequest({ meta: this.meta, command, args, - startDate: startTime, + startDate, commandId, recordCommands, callsite, @@ -161,6 +178,12 @@ export default class CoreCommandQueue { } public createSharedQueue(meta: ISessionMeta & { sessionName: string }): CoreCommandQueue { - return new CoreCommandQueue(meta, this.mode, this.connection, this.commandCounter, this.internalState); + return new CoreCommandQueue( + meta, + this.mode, + this.connection, + this.commandCounter, + this.internalState, + ); } } diff --git a/client/lib/CoreEventHeap.ts b/client/lib/CoreEventHeap.ts index d15909af6..3bc0e6c6a 100644 --- a/client/lib/CoreEventHeap.ts +++ b/client/lib/CoreEventHeap.ts @@ -56,7 +56,9 @@ export default class CoreEventHeap { startDate: new Date(), command: 'Events.addEventListener', args: [jsPath, type, options], - callsite: this.shouldIncludeCallSite() ? scriptInstance.getScriptCallSite() : null, + callsite: this.shouldIncludeCallSite() + ? JSON.stringify(scriptInstance.getScriptCallSite()) + : null, }); this.pendingRegistrations = this.pendingRegistrations.then(() => subscriptionPromise); @@ -98,7 +100,9 @@ export default class CoreEventHeap { startDate: new Date(), command: 'Events.removeEventListener', args: [listenerId, options], - callsite: this.shouldIncludeCallSite() ? scriptInstance.getScriptCallSite() : null, + callsite: this.shouldIncludeCallSite() + ? JSON.stringify(scriptInstance.getScriptCallSite()) + : null, }) .catch(error => { log.error('removeEventListener Error: ', { error, sessionId: this.meta?.sessionId }); diff --git a/client/lib/Hero.ts b/client/lib/Hero.ts index 7ff09c8d0..7aac10570 100644 --- a/client/lib/Hero.ts +++ b/client/lib/Hero.ts @@ -238,9 +238,7 @@ export default class Hero extends AwaitedEventTarget<{ } public detach(tab: Tab, key?: string): FrozenTab { - const callSitePath = getCallSite(module.filename, scriptInstance.entrypoint) - .map(x => `${x.getFileName()}:${x.getLineNumber()}:${x.getColumnNumber()}`) - .join('\n'); + const callSitePath = JSON.stringify(getCallSite(module.filename, scriptInstance.entrypoint)); const coreTab = getCoreTab(tab); const coreSession = getState(this).connection.getConnectedCoreSessionOrReject(); diff --git a/client/lib/PageState.ts b/client/lib/PageState.ts index e6c99e09f..9aa22c5c3 100644 --- a/client/lib/PageState.ts +++ b/client/lib/PageState.ts @@ -15,6 +15,7 @@ import IPageStateDefinitions, { import Tab from './Tab'; import DisconnectedFromCoreError from '../connections/DisconnectedFromCoreError'; import { CanceledPromiseError } from '@ulixee/commons/interfaces/IPendingWaitEvent'; +import ISourceCodeLocation from '@ulixee/commons/interfaces/ISourceCodeLocation'; let counter = 0; @@ -27,7 +28,7 @@ export default class PageState { readonly #coreTab: CoreTab; readonly #tab: Tab; readonly #states: T; - readonly #callsite: string; + readonly #callsite: ISourceCodeLocation[]; readonly #jsPath: IJsPath = ['page-state', (counter += 1)]; #idCounter = 0; @@ -39,7 +40,7 @@ export default class PageState { readonly #stateResolvable = new Resolvable(); readonly #batchAssertionPathToId: Record = {}; - constructor(tab: Tab, coreTab: CoreTab, states: T, callSitePath: string) { + constructor(tab: Tab, coreTab: CoreTab, states: T, callSitePath: ISourceCodeLocation[]) { this.#tab = tab; this.#coreTab = coreTab; this.#states = states ?? ({} as T); @@ -54,7 +55,7 @@ export default class PageState { const timer = new Timer(timeoutMs); const pageStateOptions: IPageStateListenArgs = { commands: this.#rawCommandsById, - callsite: this.#callsite, + callsite: JSON.stringify(this.#callsite), states: Object.keys(this.#states), }; diff --git a/client/lib/ScriptInstance.ts b/client/lib/ScriptInstance.ts index 5b8ef5d77..f865fbb51 100644 --- a/client/lib/ScriptInstance.ts +++ b/client/lib/ScriptInstance.ts @@ -2,6 +2,7 @@ import { nanoid } from 'nanoid'; import IScriptInstanceMeta from '@ulixee/hero-interfaces/IScriptInstanceMeta'; import { getCallSite } from '@ulixee/commons/lib/utils'; import ISessionCreateOptions from '@ulixee/hero-interfaces/ISessionCreateOptions'; +import ISourceCodeLocation from '@ulixee/commons/interfaces/ISourceCodeLocation'; const AwaitedDomPath = require.resolve('awaited-dom/package.json').replace('package.json', ''); const HeroLibPath = require.resolve('./Hero').replace(/\/Hero\.(?:ts|js)/, ''); @@ -50,14 +51,14 @@ export default class ScriptInstance { return name; } - public getScriptCallSite(ignoreMode = false): string { - if (!ignoreMode && this.mode === 'production') return; + public getScriptCallSite(getCallSiteRegardlessOfMode = false): ISourceCodeLocation[] { + if (!getCallSiteRegardlessOfMode && this.mode === 'production') return; const stack = getCallSite(module.filename); - let stackLines: string[] = []; + let stackLines: ISourceCodeLocation[] = []; let lastIndexOfEntrypoint = -1; for (const callSite of stack) { - const filename = callSite.getFileName(); + const { filename } = callSite; if (!filename) continue; if (filename.startsWith(HeroLibPath) || filename.startsWith(AwaitedDomPath)) continue; @@ -65,12 +66,12 @@ export default class ScriptInstance { lastIndexOfEntrypoint = stackLines.length; } - stackLines.push(`${filename}:${callSite.getLineNumber()}:${callSite.getColumnNumber()}`); + stackLines.push(callSite); } if (lastIndexOfEntrypoint >= 0) stackLines = stackLines.slice(0, lastIndexOfEntrypoint + 1); - return stackLines.join('\n'); + return stackLines; } } diff --git a/client/lib/Tab.ts b/client/lib/Tab.ts index 48fc6760c..f378d7a26 100644 --- a/client/lib/Tab.ts +++ b/client/lib/Tab.ts @@ -230,7 +230,6 @@ export default class Tab extends AwaitedEventTarget { states?: T, options: Pick = { timeoutMs: 30e3 }, ): Promise { - const callSitePath = scriptInstance.getScriptCallSite(); const coreTab = await getCoreTab(this); diff --git a/client/package.json b/client/package.json index fafa37d2b..748b5e304 100644 --- a/client/package.json +++ b/client/package.json @@ -7,7 +7,7 @@ "require": "./index.cjs" }, "dependencies": { - "@ulixee/commons": "1.5.8", + "@ulixee/commons": "1.5.9", "@ulixee/hero-interfaces": "1.5.4", "@ulixee/hero-plugin-utils": "1.5.4", "awaited-dom": "1.3.0", diff --git a/client/test/basic.test.ts b/client/test/basic.test.ts index 96775bf9a..f6d50f958 100644 --- a/client/test/basic.test.ts +++ b/client/test/basic.test.ts @@ -89,16 +89,16 @@ describe('basic Hero tests', () => { const outgoingCommands = connectionToCore.outgoing.mock.calls; - expect(outgoingCommands.filter(c => c[0].callsite)).toHaveLength(0) + expect(outgoingCommands.filter(c => c[0].callsite)).toHaveLength(0); }); }); describe('ScriptInstance tests', () => { it('should be able to properly get a script location', () => { - expect(scriptInstance.getScriptCallSite().split(/\r?\n/)).toHaveLength(1); + expect(scriptInstance.getScriptCallSite()).toHaveLength(1); (function testNested() { - expect(scriptInstance.getScriptCallSite().split(/\r?\n/)).toHaveLength(2); + expect(scriptInstance.getScriptCallSite()).toHaveLength(2); })(); }); }); diff --git a/core/package.json b/core/package.json index 4fbaa9978..2a6d546e0 100644 --- a/core/package.json +++ b/core/package.json @@ -16,7 +16,7 @@ "./connections/*": "./connections/*.js" }, "dependencies": { - "@ulixee/commons": "1.5.8", + "@ulixee/commons": "1.5.9", "@ulixee/default-browser-emulator": "1.5.4", "@ulixee/default-human-emulator": "1.5.4", "@ulixee/hero-interfaces": "1.5.4", diff --git a/fullstack/package.json b/fullstack/package.json index 3a659bf87..13391533e 100644 --- a/fullstack/package.json +++ b/fullstack/package.json @@ -7,7 +7,7 @@ "require": "./index.cjs" }, "dependencies": { - "@ulixee/commons": "1.5.8", + "@ulixee/commons": "1.5.9", "@ulixee/hero": "1.5.4", "@ulixee/hero-core": "1.5.4", "@ulixee/hero-interfaces": "1.5.4", diff --git a/interfaces/package.json b/interfaces/package.json index f9f4a8c6e..e519067ec 100644 --- a/interfaces/package.json +++ b/interfaces/package.json @@ -4,7 +4,7 @@ "description": "Core interfaces used by Hero", "dependencies": { "awaited-dom": "1.3.0", - "@ulixee/commons": "1.5.8", + "@ulixee/commons": "1.5.9", "devtools-protocol": "^0.0.799653" } } diff --git a/mitm-socket/package.json b/mitm-socket/package.json index d957714e1..bf968da37 100644 --- a/mitm-socket/package.json +++ b/mitm-socket/package.json @@ -8,7 +8,7 @@ "build-install": "npm run build" }, "dependencies": { - "@ulixee/commons": "1.5.8", + "@ulixee/commons": "1.5.9", "@ulixee/hero-interfaces": "1.5.4", "nanoid": "^3.1.30" }, diff --git a/mitm/package.json b/mitm/package.json index f8589e8fb..8c132ccfd 100644 --- a/mitm/package.json +++ b/mitm/package.json @@ -4,7 +4,7 @@ "description": "Man-in-the-middle proxy to fix chrome request/response", "main": "index.js", "dependencies": { - "@ulixee/commons": "1.5.8", + "@ulixee/commons": "1.5.9", "@ulixee/hero-interfaces": "1.5.4", "@ulixee/hero-mitm-socket": "1.5.4", "better-sqlite3": "^7.4.1", diff --git a/plugin-utils/package.json b/plugin-utils/package.json index ce808b930..63c259ddf 100644 --- a/plugin-utils/package.json +++ b/plugin-utils/package.json @@ -5,7 +5,7 @@ "scripts": {}, "dependencies": { "@ulixee/chrome-app": "1.0.2", - "@ulixee/commons": "1.5.8", + "@ulixee/commons": "1.5.9", "@ulixee/hero-interfaces": "1.5.4", "progress": "^2.0.3", "tar": "^6.1.11" diff --git a/plugins/default-browser-emulator/package.json b/plugins/default-browser-emulator/package.json index 817065626..696b0e46c 100644 --- a/plugins/default-browser-emulator/package.json +++ b/plugins/default-browser-emulator/package.json @@ -5,7 +5,7 @@ "main": "index.js", "dependencies": { "@ulixee/chrome-89-0": "^4389.128.4", - "@ulixee/commons": "1.5.8", + "@ulixee/commons": "1.5.9", "@ulixee/hero-interfaces": "1.5.4", "@ulixee/hero-plugin-utils": "1.5.4", "compare-versions": "^3.6.0", diff --git a/plugins/default-human-emulator/package.json b/plugins/default-human-emulator/package.json index b56122610..c790235cd 100644 --- a/plugins/default-human-emulator/package.json +++ b/plugins/default-human-emulator/package.json @@ -8,6 +8,6 @@ "@ulixee/hero-plugin-utils": "1.5.4" }, "devDependencies": { - "@ulixee/commons": "1.5.8" + "@ulixee/commons": "1.5.9" } } diff --git a/plugins/execute-js/package.json b/plugins/execute-js/package.json index 81d1e45bc..99307ef9c 100644 --- a/plugins/execute-js/package.json +++ b/plugins/execute-js/package.json @@ -8,7 +8,7 @@ "@ulixee/hero-plugin-utils": "1.5.4" }, "devDependencies": { - "@ulixee/commons": "1.5.8", + "@ulixee/commons": "1.5.9", "@ulixee/hero-core": "1.5.4", "@ulixee/hero-fullstack": "1.5.4", "@ulixee/execute-js-plugin": "1.5.4", diff --git a/puppet-chrome/package.json b/puppet-chrome/package.json index 5061b8deb..a1c04a9ef 100644 --- a/puppet-chrome/package.json +++ b/puppet-chrome/package.json @@ -3,7 +3,7 @@ "version": "1.5.4", "description": "Puppet driver for chrome", "dependencies": { - "@ulixee/commons": "1.5.8", + "@ulixee/commons": "1.5.9", "@ulixee/hero-interfaces": "1.5.4", "devtools-protocol": "^0.0.799653" } diff --git a/puppet/package.json b/puppet/package.json index 1d701e849..56e647f6b 100644 --- a/puppet/package.json +++ b/puppet/package.json @@ -3,7 +3,7 @@ "version": "1.5.4", "description": "Puppet driver", "dependencies": { - "@ulixee/commons": "1.5.8", + "@ulixee/commons": "1.5.9", "@ulixee/hero-interfaces": "1.5.4", "@ulixee/hero-puppet-chrome": "1.5.4", "ws": "^7.4.6" diff --git a/testing/package.json b/testing/package.json index d8d8d0f23..29bda520f 100644 --- a/testing/package.json +++ b/testing/package.json @@ -10,7 +10,7 @@ "dependencies": { "@koa/multer": "^3.0.0", "@koa/router": "^8.0.8", - "@ulixee/commons": "1.5.8", + "@ulixee/commons": "1.5.9", "@ulixee/hero-core": "1.5.4", "@ulixee/hero-interfaces": "1.5.4", "@ulixee/hero-mitm-socket": "1.5.4", diff --git a/timetravel/package.json b/timetravel/package.json index 251407732..8b9159e96 100644 --- a/timetravel/package.json +++ b/timetravel/package.json @@ -3,7 +3,7 @@ "version": "1.5.4", "description": "The interface to playback and examine previous Hero sessions", "dependencies": { - "@ulixee/commons": "1.5.8", + "@ulixee/commons": "1.5.9", "@ulixee/hero-interfaces": "1.5.4", "@ulixee/hero-core": "1.5.4", "nanoid": "^3.1.30" diff --git a/yarn.lock b/yarn.lock index 050b7f480..73206c0b9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7509,6 +7509,11 @@ sort-keys@^4.0.0: dependencies: is-plain-obj "^2.0.0" +source-map-js@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/source-map-js/-/source-map-js-1.0.1.tgz#a1741c131e3c77d048252adfa24e23b908670caf" + integrity sha512-4+TN2b3tqOCd/kaGRJ/sTYA0tR0mdXx26ipdolxcwtJVqEnqNYvlCAt1q3ypy4QMlYus+Zh34RNtYLoq2oQ4IA== + source-map-loader@^0.2.4: version "0.2.4" resolved "https://registry.yarnpkg.com/source-map-loader/-/source-map-loader-0.2.4.tgz#c18b0dc6e23bf66f6792437557c569a11e072271" @@ -7517,7 +7522,7 @@ source-map-loader@^0.2.4: async "^2.5.0" loader-utils "^1.1.0" -source-map-support@^0.5.19, source-map-support@^0.5.6: +source-map-support@^0.5.6: version "0.5.20" resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.20.tgz#12166089f8f5e5e8c56926b377633392dd2cb6c9" integrity sha512-n1lZZ8Ve4ksRqizaBQgxXDgKwttHDhyfQjA6YZZn8+AroHbsIz+JjwxQDxbp+7y5OYCI8t1Yk7etjD9CRd2hIw==