Skip to content

Commit 8d866e5

Browse files
committed
simplify: remove normalizeWaitTimeoutMs helper, fix sinafinance timeout
Per review feedback, the simpler fix is to enforce one consistent unit (seconds) and correct the one wrong call site instead of introducing auto-detecting threshold logic.
1 parent cbbb893 commit 8d866e5

5 files changed

Lines changed: 5 additions & 47 deletions

File tree

src/browser/cdp.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import { request as httpsRequest } from 'node:https';
1414
import type { BrowserCookie, IPage, ScreenshotOptions, SnapshotOptions, WaitOptions } from '../types.js';
1515
import type { IBrowserFactory } from '../runtime.js';
1616
import { wrapForEval } from './utils.js';
17-
import { normalizeWaitTimeoutMs } from './wait.js';
1817
import { generateSnapshotJs, scrollToRefJs, getFormStateJs } from './dom-snapshot.js';
1918
import { generateStealthJs } from './stealth.js';
2019
import {
@@ -268,12 +267,12 @@ class CDPPage implements IPage {
268267
return;
269268
}
270269
if (options.selector) {
271-
const timeout = normalizeWaitTimeoutMs(options.timeout, 10);
270+
const timeout = (options.timeout ?? 10) * 1000;
272271
await this.evaluate(waitForSelectorJs(options.selector, timeout));
273272
return;
274273
}
275274
if (options.text) {
276-
const timeout = normalizeWaitTimeoutMs(options.timeout, 30);
275+
const timeout = (options.timeout ?? 30) * 1000;
277276
await this.evaluate(waitForTextJs(options.text, timeout));
278277
}
279278
}

src/browser/page.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import { formatSnapshot } from '../snapshotFormatter.js';
1414
import type { BrowserCookie, IPage, ScreenshotOptions, SnapshotOptions, WaitOptions } from '../types.js';
1515
import { sendCommand } from './daemon-client.js';
1616
import { wrapForEval } from './utils.js';
17-
import { normalizeWaitTimeoutMs } from './wait.js';
1817
import { saveBase64ToFile } from '../utils.js';
1918
import { generateSnapshotJs, scrollToRefJs, getFormStateJs } from './dom-snapshot.js';
2019
import { generateStealthJs } from './stealth.js';
@@ -240,13 +239,13 @@ export class Page implements IPage {
240239
return;
241240
}
242241
if (options.selector) {
243-
const timeout = normalizeWaitTimeoutMs(options.timeout, 10);
242+
const timeout = (options.timeout ?? 10) * 1000;
244243
const code = waitForSelectorJs(options.selector, timeout);
245244
await sendCommand('exec', { code, ...this._cmdOpts() });
246245
return;
247246
}
248247
if (options.text) {
249-
const timeout = normalizeWaitTimeoutMs(options.timeout, 30);
248+
const timeout = (options.timeout ?? 30) * 1000;
250249
const code = waitForTextJs(options.text, timeout);
251250
await sendCommand('exec', { code, ...this._cmdOpts() });
252251
}

src/browser/wait.test.ts

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/browser/wait.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export interface WaitOptions {
2828
text?: string;
2929
selector?: string; // wait until document.querySelector(selector) matches
3030
time?: number;
31-
timeout?: number; // seconds by default; values >= 1000 are treated as ms for backward compatibility
31+
timeout?: number;
3232
}
3333

3434
export interface ScreenshotOptions {

0 commit comments

Comments
 (0)