channel-worker 1.0.8 → 1.0.9
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/lib/nst-manager.js +17 -34
- package/package.json +1 -1
package/lib/nst-manager.js
CHANGED
|
@@ -125,43 +125,26 @@ class NstManager {
|
|
|
125
125
|
await this.setProxy(profileId, options.proxy);
|
|
126
126
|
}
|
|
127
127
|
|
|
128
|
-
|
|
129
|
-
const
|
|
130
|
-
|
|
128
|
+
// Use connectBrowser instead of startBrowser — allows passing --load-extension args
|
|
129
|
+
const connectConfig = {
|
|
130
|
+
headless: false,
|
|
131
|
+
autoClose: false,
|
|
132
|
+
};
|
|
131
133
|
|
|
132
|
-
//
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
if (wsUrl) {
|
|
140
|
-
const WebSocket = require('ws');
|
|
141
|
-
const ws = new WebSocket(wsUrl);
|
|
142
|
-
await new Promise((resolve, reject) => {
|
|
143
|
-
const timeout = setTimeout(() => { ws.close(); reject(new Error('CDP timeout')); }, 10000);
|
|
144
|
-
ws.on('open', () => {
|
|
145
|
-
// Navigate a new tab to set storage
|
|
146
|
-
ws.send(JSON.stringify({
|
|
147
|
-
id: 1,
|
|
148
|
-
method: 'Runtime.evaluate',
|
|
149
|
-
params: {
|
|
150
|
-
expression: `chrome.storage && chrome.storage.local ? chrome.storage.local.set({nstProfileId: "${profileIdOrName}"}) : null`,
|
|
151
|
-
awaitPromise: true,
|
|
152
|
-
},
|
|
153
|
-
}));
|
|
154
|
-
setTimeout(() => { clearTimeout(timeout); ws.close(); resolve(); }, 2000);
|
|
155
|
-
});
|
|
156
|
-
ws.on('error', (e) => { clearTimeout(timeout); reject(e); });
|
|
157
|
-
});
|
|
158
|
-
console.log(`[nst] Profile ID "${profileIdOrName}" set in extension storage`);
|
|
159
|
-
}
|
|
160
|
-
} catch (e) {
|
|
161
|
-
console.log(`[nst] Could not set profile ID in storage: ${e.message}`);
|
|
134
|
+
// Add extension path if provided
|
|
135
|
+
if (options.extensionPath) {
|
|
136
|
+
connectConfig.args = {
|
|
137
|
+
'--load-extension': options.extensionPath,
|
|
138
|
+
'--disable-extensions-except': options.extensionPath,
|
|
139
|
+
};
|
|
140
|
+
console.log(`[nst] Loading extension: ${options.extensionPath}`);
|
|
162
141
|
}
|
|
163
142
|
|
|
164
|
-
|
|
143
|
+
console.log(`[nst] Connecting browser for profile: ${profileId}`);
|
|
144
|
+
const res = await this.client.cdpEndpoints().connectBrowser(profileId, connectConfig);
|
|
145
|
+
console.log(`[nst] Browser started`);
|
|
146
|
+
|
|
147
|
+
return { profileId, wsEndpoint: res?.data?.webSocketDebuggerUrl, response: res };
|
|
165
148
|
}
|
|
166
149
|
|
|
167
150
|
// Stop browser
|