Skip to content

Commit e9c4c24

Browse files
zknprclaude
andcommitted
fix(web): load worker via Blob URL in VS Code Web
Web Workers cannot load scripts from vscode-vfs:// URIs directly. Use vsc.workspace.fs to read the worker script content and create a Blob URL for Worker instantiation. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 383c07f commit e9c4c24

3 files changed

Lines changed: 24 additions & 7 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## 1.2.7
4+
5+
### Bug Fixes
6+
7+
- **VS Code Web Worker Loading**: Fixed database files not loading in VS Code Web. Web Workers cannot load scripts from `vscode-vfs://` URIs directly. Now uses the VS Code workspace.fs API to read the worker script and creates a Blob URL for Worker instantiation.
8+
39
## 1.2.6
410

511
### Bug Fixes

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"name": "sqlite-explorer",
44
"displayName": "SQLite Explorer",
55
"description": "A powerful SQLite database viewer and editor for VS Code",
6-
"version": "1.2.6",
6+
"version": "1.2.7",
77
"publisher": "zknpr",
88
"license": "MIT",
99
"repository": {

src/workerFactory.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,24 @@ async function createWasmDatabaseConnection(
174174
extensionUri: vsc.Uri,
175175
_reporter?: TelemetryReporter
176176
): Promise<DatabaseConnectionBundle> {
177-
// Determine worker script path based on environment
178-
const workerScriptPath = import.meta.env.VSCODE_BROWSER_EXT
179-
? vsc.Uri.joinPath(extensionUri, 'out', 'worker-browser.js').toString()
180-
: path.resolve(__dirname, './worker.cjs');
181-
182177
// Spawn worker thread
183-
const workerThread = new Worker(workerScriptPath);
178+
// Browser: Web Workers can't load from vscode-vfs:// URIs directly.
179+
// Use fetch to load the worker script as a Blob and create a Blob URL.
180+
// Node.js: Use require path directly.
181+
let workerThread: InstanceType<typeof Worker>;
182+
183+
if (import.meta.env.VSCODE_BROWSER_EXT) {
184+
// Browser environment: fetch worker script and create Blob URL
185+
const workerScriptUri = vsc.Uri.joinPath(extensionUri, 'out', 'worker-browser.js');
186+
const workerContent = await vsc.workspace.fs.readFile(workerScriptUri);
187+
const blob = new Blob([workerContent], { type: 'application/javascript' });
188+
const blobUrl = URL.createObjectURL(blob);
189+
workerThread = new Worker(blobUrl);
190+
} else {
191+
// Node.js environment: use file path directly
192+
const workerScriptPath = path.resolve(__dirname, './worker.cjs');
193+
workerThread = new Worker(workerScriptPath);
194+
}
184195

185196
// Create IPC proxy for worker communication
186197
// Browser Workers use addEventListener, Node.js Workers use .on()

0 commit comments

Comments
 (0)