Skip to content

Commit

Permalink
fix(timetravel): unidentified frames break replay
Browse files Browse the repository at this point in the history
  • Loading branch information
blakebyrnes committed Feb 10, 2022
1 parent 9792756 commit 708e2dd
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 46 deletions.
1 change: 0 additions & 1 deletion client/lib/CoreCommandQueue.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import ISessionMeta from '@ulixee/hero-interfaces/ISessionMeta';
import SourceLoader from '@ulixee/commons/lib/SourceLoader';
import { CanceledPromiseError } from '@ulixee/commons/interfaces/IPendingWaitEvent';
import ISourceCodeLocation from '@ulixee/commons/interfaces/ISourceCodeLocation';
import Queue from '@ulixee/commons/lib/Queue';
import ICoreRequestPayload from '@ulixee/hero-interfaces/ICoreRequestPayload';
import ConnectionToCore from '../connections/ConnectionToCore';
Expand Down
12 changes: 1 addition & 11 deletions client/test/basic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ describe('basic Hero tests', () => {
]);
});

it('includes callsites during non-production mode', async () => {
it('includes callsites for commands', async () => {
const connectionToCore = new MockedConnectionToCore();
const hero = await new Hero({ connectionToCore });
await hero.close();
Expand All @@ -81,16 +81,6 @@ describe('basic Hero tests', () => {
// Core.connect doesn't run over a command queue, so never gets callsites
expect(outgoingCommands.filter(c => c[0].callsite)).toHaveLength(2);
});

it('does not include callsites during non-production mode', async () => {
const connectionToCore = new MockedConnectionToCore();
const hero = await new Hero({ connectionToCore, mode: 'production' });
await hero.close();

const outgoingCommands = connectionToCore.outgoing.mock.calls;

expect(outgoingCommands.filter(c => c[0].callsite)).toHaveLength(0);
});
});

describe('ScriptInstance tests', () => {
Expand Down
4 changes: 2 additions & 2 deletions fullstack/test/interact.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Helpers } from '@ulixee/hero-testing';
import { KeyboardKey } from '@ulixee/hero-interfaces/IKeyboardLayoutUS';
import { Command } from '@ulixee/hero/interfaces/IInteractions';
import { createSession, ITestKoaServer } from '@ulixee/hero-testing/helpers';
import { ITestKoaServer } from '@ulixee/hero-testing/helpers';
import HumanEmulator from '@ulixee/hero-plugin-utils/lib/HumanEmulator';
import Hero, { Core, InteractionCommand, LocationStatus } from '../index';
import Hero, { Core, LocationStatus } from '../index';
import Session from '@ulixee/hero-core/lib/Session';

let koaServer: ITestKoaServer;
Expand Down
5 changes: 3 additions & 2 deletions timetravel/lib/MirrorPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ export default class MirrorPage extends TypedEventEmitter<{
this.page.on('console', msg => {
log.info('MirrorPage.console', {
...msg,
sessionId: this.sessionId,
sessionId,
});
});
this.page.on('crashed', msg => {
log.info('MirrorPage.crashed', {
...msg,
sessionId: this.sessionId,
sessionId,
});
});
}
Expand Down Expand Up @@ -481,6 +481,7 @@ export default class MirrorPage extends TypedEventEmitter<{
for (const [${columns.join(',')}] of event) {
const event = { ${columns.join(',')} };
event.frameIdPath = domNodePathsByFrameId[frameId];
if (frameId && !event.frameIdPath) continue;
if (event.tagName !== undefined) event.tagName = tagNamesById[event.tagName];
changeEvents.push(event);
}
Expand Down
46 changes: 16 additions & 30 deletions timetravel/lib/TimelineRecorder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,20 @@ export default class TimelineRecorder extends TypedEventEmitter<{
super();
bindFunctions(this);

this.registeredEvents = addTypedEventListeners(heroSession, [
['tab-created', this.onTabCreated],
['kept-alive', this.onHeroSessionPaused],
['will-close', this.onHeroSessionWillClose],
[
'closed',
() => {
heroSession.off('tab-created', this.onTabCreated);
},
],
]);
const tabCreatedEvent = addTypedEventListener(heroSession, 'tab-created', this.onTabCreated);
const removeTabCreated = removeEventListeners.bind(null, [tabCreatedEvent]);
this.registeredEvents = [tabCreatedEvent];
this.registeredEvents.push(
...addTypedEventListeners(heroSession, [
['will-close', this.onHeroSessionWillClose],
['closed', removeTabCreated],
]),
);
}

public stop(): void {
if (!this.heroSession) return;
removeEventListeners(this.registeredEvents);
this.stopRecording();
this.dontExtendSessionPastTime();
}

Expand All @@ -61,15 +58,6 @@ export default class TimelineRecorder extends TypedEventEmitter<{
}
}

public stopRecording(): void {
for (const tab of this.heroSession.tabsById.values()) {
tab
.stopRecording()
.then(() => this.emit('updated'))
.catch(console.error);
}
}

public getScreenshot(tabId: number, timestamp: number): string {
const image = this.heroSession.db.screenshots.getImage(tabId, timestamp);
if (image) return image.toString('base64');
Expand Down Expand Up @@ -105,18 +93,16 @@ export default class TimelineRecorder extends TypedEventEmitter<{
}
}

private onHeroSessionPaused(): void {
if (!this.heroSession) return;
this.stopRecording();
}

private onTabCreated(event: { tab: Tab }): void {
const tab = event.tab;
const statusChangeEvent = addTypedEventListener(
tab.navigations,
'status-change',
this.onStatusChange,
);
this.registeredEvents.push(
addTypedEventListener(tab.navigations, 'status-change', this.onStatusChange),
addTypedEventListener(tab, 'close', () => {
tab.navigations.off('status-change', this.onStatusChange);
}),
statusChangeEvent,
addTypedEventListener(tab, 'close', () => removeEventListeners([statusChangeEvent])),
);
}

Expand Down

0 comments on commit 708e2dd

Please sign in to comment.