channel-worker 1.0.10 → 1.0.11

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/lib/nst-manager.js +14 -18
  2. package/package.json +1 -1
@@ -10,6 +10,7 @@ class NstManager {
10
10
  if (!NstBrowserV2) {
11
11
  throw new Error('nstbrowser-sdk-node not installed. Run: npm install -g nstbrowser-sdk-node');
12
12
  }
13
+ this.apiKey = apiKey;
13
14
  this.client = new NstBrowserV2(apiKey, {
14
15
  timeout: options.timeout || 60000,
15
16
  apiAddress: options.apiAddress || 'http://localhost:8848/api/v2',
@@ -57,7 +58,7 @@ class NstManager {
57
58
  }
58
59
 
59
60
  // Create profile if not exists, return profileId
60
- async ensureProfile(name, options = {}) {
61
+ async ensureProfile(name) {
61
62
  const existing = await this.findProfile(name);
62
63
  if (existing) {
63
64
  console.log(`[nst] Profile "${name}" exists: ${existing}`);
@@ -65,7 +66,7 @@ class NstManager {
65
66
  }
66
67
 
67
68
  console.log(`[nst] Creating profile "${name}"...`);
68
- const profileData = {
69
+ const res = await this.client.profiles().createProfile({
69
70
  name,
70
71
  platform: 'Windows',
71
72
  kernelMilestone: '132',
@@ -80,17 +81,7 @@ class NstManager {
80
81
  hardwareConcurrency: 8,
81
82
  deviceMemory: 8,
82
83
  },
83
- };
84
-
85
- // Add extension load arg if provided
86
- if (options.extensionPath) {
87
- profileData.args = {
88
- '--load-extension': options.extensionPath,
89
- '--disable-extensions-except': options.extensionPath,
90
- };
91
- }
92
-
93
- const res = await this.client.profiles().createProfile(profileData);
84
+ });
94
85
 
95
86
  const profileId = res?.data?.profileId || res?.data?._id;
96
87
  if (!profileId) throw new Error('Failed to create profile — no ID returned');
@@ -111,7 +102,7 @@ class NstManager {
111
102
  async launchProfile(profileIdOrName, options = {}) {
112
103
  let profileId = profileIdOrName;
113
104
  if (!this.isUUID(profileIdOrName)) {
114
- profileId = await this.ensureProfile(profileIdOrName, { extensionPath: options.extensionPath });
105
+ profileId = await this.ensureProfile(profileIdOrName);
115
106
  }
116
107
 
117
108
  // If already running, stop first to reload with fresh extension
@@ -126,13 +117,11 @@ class NstManager {
126
117
  await this.setProxy(profileId, options.proxy);
127
118
  }
128
119
 
129
- // Use connectBrowser instead of startBrowser — allows passing --load-extension args
130
120
  const connectConfig = {
131
121
  headless: false,
132
122
  autoClose: false,
133
123
  };
134
124
 
135
- // Add extension path if provided
136
125
  if (options.extensionPath) {
137
126
  connectConfig.args = {
138
127
  '--load-extension': options.extensionPath,
@@ -142,9 +131,16 @@ class NstManager {
142
131
  }
143
132
 
144
133
  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
134
 
135
+ // SDK uses axios which serializes nested objects as config[key]=value
136
+ // But Nstbrowser API expects ?config=<JSON-string>
137
+ // Workaround: call the API directly with fetch instead of SDK
138
+ const apiUrl = `http://localhost:8848/api/v2/connect/${profileId}?config=${encodeURIComponent(JSON.stringify(connectConfig))}`;
139
+ const rawRes = await fetch(apiUrl, { headers: { 'x-api-key': this.apiKey } });
140
+ const res = await rawRes.json();
141
+ if (res.err) throw new Error(res.msg || 'Failed to connect browser');
142
+
143
+ console.log(`[nst] Browser started`);
148
144
  return { profileId, wsEndpoint: res?.data?.webSocketDebuggerUrl, response: res };
149
145
  }
150
146
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "channel-worker",
3
- "version": "1.0.10",
3
+ "version": "1.0.11",
4
4
  "description": "Channel Manager worker daemon — runs on remote machines to execute video pipeline jobs",
5
5
  "main": "lib/daemon.js",
6
6
  "bin": {