playwright-browser-handler 1.0.3 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -66,6 +66,7 @@ await browser.context.storageState({ path: 'auth.json' });
66
66
  - One-line launch of **Chromium, Firefox or WebKit** (or your installed Chrome/Edge via `channel`)
67
67
  - Open and close browser sessions and tabs
68
68
  - Set cookies before the first navigation — Chrome cookie exports work as-is
69
+ - Resume a saved login with `storageState` (save it with `browser.context.storageState({ path })`), with your own `userAgent`, `locale` and `timezoneId`
69
70
  - Sensible defaults: 1920×1080 viewport, 60 s navigation timeout, headless
70
71
 
71
72
  ### 🔍 Page Navigation and Interaction
@@ -118,6 +119,10 @@ const browser = new BrowserHandler(downloadPath = './downloads', { logLevel = 'i
118
119
  | `channel` | `string` | — | `'chrome'`, `'msedge'`… to use an installed browser |
119
120
  | `executablePath` | `string` | — | Use a specific browser binary |
120
121
  | `timeout` | `number` | — | Launch timeout in ms |
122
+ | `storageState` | `string \| StorageState` | — | Saved session to resume: a JSON file path or the object from `context.storageState()` |
123
+ | `userAgent` | `string` | — | User agent for the context |
124
+ | `locale` | `string` | — | Locale, e.g. `'en-US'` (`navigator.language`, `Accept-Language`, formatting) |
125
+ | `timezoneId` | `string` | — | Time zone, e.g. `'Asia/Jerusalem'` |
121
126
 
122
127
  ### Navigation & interaction
123
128
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "playwright-browser-handler",
3
- "version": "1.0.3",
3
+ "version": "1.1.1",
4
4
  "description": "A convenient Playwright wrapper for browser automation. One line to open a browser, then navigate, click, fill forms, scrape links, take screenshots and collect downloads — with full access to Playwright underneath. Same API as puppet-browser-handler.",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -9,6 +9,7 @@ const DEFAULT_VIEWPORT = { width: 1920, height: 1080 };
9
9
  const DEFAULT_NAVIGATION_TIMEOUT = 60_000;
10
10
  const COOKIE_FIELDS = ["name", "value", "url", "domain", "path", "expires", "httpOnly", "secure", "sameSite"];
11
11
  const SAME_SITE = { strict: "Strict", lax: "Lax", none: "None", no_restriction: "None" };
12
+ const CONTEXT_FIELDS = ["storageState", "userAgent", "locale", "timezoneId"];
12
13
 
13
14
  export default class BrowserHandler {
14
15
  /**
@@ -65,7 +66,8 @@ export default class BrowserHandler {
65
66
  if (!engine) throw new Error(`Unknown browser "${options.browser}". Use "chromium", "firefox" or "webkit".`);
66
67
  const { headless, slowMo, args, channel, executablePath, timeout } = options;
67
68
  this._browser = await engine.launch({ headless, slowMo, args, channel, executablePath, timeout });
68
- this._context = await this._browser.newContext({ viewport: options.viewport, acceptDownloads: true });
69
+ const contextOptions = pickDefined(options, CONTEXT_FIELDS);
70
+ this._context = await this._browser.newContext({ viewport: options.viewport, acceptDownloads: true, ...contextOptions });
69
71
  this._navigationTimeout = options.navigationTimeout;
70
72
  this._page = await this._newPage();
71
73
  }
@@ -273,6 +275,10 @@ function normalizeCookie(cookie) {
273
275
  return clean;
274
276
  }
275
277
 
278
+ function pickDefined(source, keys) {
279
+ return Object.fromEntries(keys.filter((key) => source[key] !== undefined).map((key) => [key, source[key]]));
280
+ }
281
+
276
282
  function screenshotType(fileExt) {
277
283
  return /^jpe?g$/i.test(fileExt) ? "jpeg" : "png";
278
284
  }
package/src/index.d.ts CHANGED
@@ -22,6 +22,26 @@ export interface CookieInput {
22
22
  [extra: string]: unknown;
23
23
  }
24
24
 
25
+ /**
26
+ * Playwright's storage state, e.g. what `context.storageState()` returns. Passed to Playwright as-is:
27
+ * cookies need `url`, or `domain` + `path`, and `sameSite` must be "Strict" | "Lax" | "None".
28
+ */
29
+ export interface StorageState {
30
+ cookies: Array<{
31
+ name: string;
32
+ value: string;
33
+ url?: string;
34
+ domain?: string;
35
+ path?: string;
36
+ /** Unix time in seconds. */
37
+ expires?: number;
38
+ httpOnly?: boolean;
39
+ secure?: boolean;
40
+ sameSite?: "Strict" | "Lax" | "None";
41
+ }>;
42
+ origins: Array<{ origin: string; localStorage: Array<{ name: string; value: string }> }>;
43
+ }
44
+
25
45
  export interface OpenBrowserOptions {
26
46
  /** Which engine to launch. Default: "chromium". */
27
47
  browser?: BrowserName;
@@ -43,6 +63,14 @@ export interface OpenBrowserOptions {
43
63
  executablePath?: string;
44
64
  /** Launch timeout in ms. */
45
65
  timeout?: number;
66
+ /** Resume a saved session: a path to a JSON file or the object from `context.storageState()`. */
67
+ storageState?: string | StorageState;
68
+ /** User agent for the context. Default: the browser's own. */
69
+ userAgent?: string;
70
+ /** Locale for the context, e.g. "en-US". Default: the system locale. */
71
+ locale?: string;
72
+ /** Time zone for the context, e.g. "Asia/Jerusalem". Default: the system time zone. */
73
+ timezoneId?: string;
46
74
  }
47
75
 
48
76
  export interface BrowserHandlerOptions {