websession-api-client 0.0.3 → 0.0.4

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.
Files changed (2) hide show
  1. package/index.js +37 -0
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ const fs = require('fs');
1
2
  const puppeteer = require('puppeteer-extra');
2
3
  const StealthPlugin = require('puppeteer-extra-plugin-stealth');
3
4
 
@@ -5,6 +6,36 @@ puppeteer.use(StealthPlugin());
5
6
 
6
7
  const DEFAULT_USER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36';
7
8
 
9
+ // Resolve Chrome executable in order of preference:
10
+ // 1. PUPPETEER_EXECUTABLE_PATH env var (set in Docker/CI)
11
+ // 2. Common system-installed Chrome/Chromium paths
12
+ // 3. Puppeteer's own downloaded Chrome (falls back to its default)
13
+ function resolveChromePath() {
14
+ if (process.env.PUPPETEER_EXECUTABLE_PATH) {
15
+ return process.env.PUPPETEER_EXECUTABLE_PATH;
16
+ }
17
+
18
+ const candidates = [
19
+ '/usr/bin/google-chrome-stable',
20
+ '/usr/bin/google-chrome',
21
+ '/usr/bin/chromium-browser',
22
+ '/usr/bin/chromium',
23
+ '/snap/bin/chromium',
24
+ ];
25
+
26
+ for (const candidate of candidates) {
27
+ try {
28
+ fs.accessSync(candidate, fs.constants.X_OK);
29
+ return candidate;
30
+ } catch {
31
+ // not found, try next
32
+ }
33
+ }
34
+
35
+ // Let Puppeteer use its own downloaded Chrome
36
+ return null;
37
+ }
38
+
8
39
  class ApiExtractor {
9
40
  constructor() {
10
41
  this.browser = null;
@@ -21,6 +52,11 @@ class ApiExtractor {
21
52
  async init(options = {}) {
22
53
  console.log('starting browser...');
23
54
 
55
+ const chromePath = options.executablePath || resolveChromePath();
56
+ if (chromePath) {
57
+ console.log('Using Chrome at:', chromePath);
58
+ }
59
+
24
60
  const defaultArgs = [
25
61
  '--no-sandbox',
26
62
  '--disable-setuid-sandbox',
@@ -37,6 +73,7 @@ class ApiExtractor {
37
73
 
38
74
  const puppeteerConfig = {
39
75
  headless: true,
76
+ ...(chromePath ? { executablePath: chromePath } : {}),
40
77
  ...options,
41
78
  args: options.args ? [...defaultArgs, ...options.args] : defaultArgs
42
79
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "websession-api-client",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "description": "",
5
5
  "license": "ISC",
6
6
  "author": "",