Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion packages/playwright-core/src/utils/isomorphic/time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@
* limitations under the License.
*/

let _timeOrigin = performance.timeOrigin;
let _timeShift = 0;

export function setTimeOrigin(origin: number) {
_timeOrigin = origin;
_timeShift = performance.timeOrigin - origin;
}

export function timeOrigin(): number {
return _timeOrigin;
}

export function monotonicTime(): number {
return Math.floor(performance.now() * 1000) / 1000;
return Math.floor((performance.now() + _timeShift) * 1000) / 1000;
}
1 change: 1 addition & 0 deletions packages/playwright/src/common/ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export type SerializedConfig = {
};

export type ProcessInitParams = {
timeOrigin: number;
processName: string;
};

Expand Down
3 changes: 2 additions & 1 deletion packages/playwright/src/common/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { startProfiling, stopProfiling } from 'playwright-core/lib/utils';
import { setTimeOrigin, startProfiling, stopProfiling } from 'playwright-core/lib/utils';

import { serializeError } from '../util';
import { registerESMLoader } from './esmLoaderHost';
Expand Down Expand Up @@ -69,6 +69,7 @@ process.on('message', async (message: any) => {
if (message.method === '__init__') {
const { processParams, runnerParams, runnerScript } = message.params as { processParams: ProcessInitParams, runnerParams: any, runnerScript: string };
void startProfiling();
setTimeOrigin(processParams.timeOrigin);
const { create } = require(runnerScript);
processRunner = create(runnerParams) as ProcessRunner;
processName = processParams.processName;
Expand Down
5 changes: 3 additions & 2 deletions packages/playwright/src/runner/processHost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import child_process from 'child_process';
import { EventEmitter } from 'events';

import { assert } from 'playwright-core/lib/utils';
import { assert, timeOrigin } from 'playwright-core/lib/utils';
import { debug } from 'playwright-core/lib/utilsBundle';

import { esmLoaderRegistered } from '../common/esmLoaderHost';
Expand Down Expand Up @@ -115,7 +115,8 @@ export class ProcessHost extends EventEmitter {
return error;

const processParams: ProcessInitParams = {
processName: this._processName
processName: this._processName,
timeOrigin: timeOrigin(),
};

this.send({
Expand Down
Loading