channel-worker 1.0.8 → 1.0.10
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 +21 -37
- package/package.json +1 -1
package/lib/nst-manager.js
CHANGED
|
@@ -114,10 +114,11 @@ class NstManager {
|
|
|
114
114
|
profileId = await this.ensureProfile(profileIdOrName, { extensionPath: options.extensionPath });
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
-
//
|
|
117
|
+
// If already running, stop first to reload with fresh extension
|
|
118
118
|
if (await this.isProfileRunning(profileId)) {
|
|
119
|
-
console.log(`[nst] Profile ${profileId} already running —
|
|
120
|
-
|
|
119
|
+
console.log(`[nst] Profile ${profileId} already running — restarting to load extension`);
|
|
120
|
+
await this.stopProfile(profileId);
|
|
121
|
+
await new Promise(r => setTimeout(r, 3000)); // wait for browser to close
|
|
121
122
|
}
|
|
122
123
|
|
|
123
124
|
// Set proxy before launch
|
|
@@ -125,43 +126,26 @@ class NstManager {
|
|
|
125
126
|
await this.setProxy(profileId, options.proxy);
|
|
126
127
|
}
|
|
127
128
|
|
|
128
|
-
|
|
129
|
-
const
|
|
130
|
-
|
|
129
|
+
// Use connectBrowser instead of startBrowser — allows passing --load-extension args
|
|
130
|
+
const connectConfig = {
|
|
131
|
+
headless: false,
|
|
132
|
+
autoClose: false,
|
|
133
|
+
};
|
|
131
134
|
|
|
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}`);
|
|
135
|
+
// Add extension path if provided
|
|
136
|
+
if (options.extensionPath) {
|
|
137
|
+
connectConfig.args = {
|
|
138
|
+
'--load-extension': options.extensionPath,
|
|
139
|
+
'--disable-extensions-except': options.extensionPath,
|
|
140
|
+
};
|
|
141
|
+
console.log(`[nst] Loading extension: ${options.extensionPath}`);
|
|
162
142
|
}
|
|
163
143
|
|
|
164
|
-
|
|
144
|
+
console.log(`[nst] Connecting browser for profile: ${profileId}`);
|
|
145
|
+
const res = await this.client.cdpEndpoints().connectBrowser(profileId, connectConfig);
|
|
146
|
+
console.log(`[nst] Browser started`);
|
|
147
|
+
|
|
148
|
+
return { profileId, wsEndpoint: res?.data?.webSocketDebuggerUrl, response: res };
|
|
165
149
|
}
|
|
166
150
|
|
|
167
151
|
// Stop browser
|