Skip to content

Commit bff5c65

Browse files
authored
fix: handle the case when all pages are filtered out (#616)
Drive-by: allow attaching to chrome://inspect pages
1 parent c458fd1 commit bff5c65

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

src/McpContext.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,10 @@ export class McpContext implements Context {
407407
);
408408
});
409409

410-
if (!this.#selectedPage || this.#pages.indexOf(this.#selectedPage) === -1) {
410+
if (
411+
(!this.#selectedPage || this.#pages.indexOf(this.#selectedPage) === -1) &&
412+
this.#pages[0]
413+
) {
411414
this.selectPage(this.#pages[0]);
412415
}
413416

src/browser.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ function makeTargetFilter() {
3030
if (target.url() === 'chrome://newtab/') {
3131
return true;
3232
}
33+
// Could be the only page opened in the browser.
34+
if (target.url().startsWith('chrome://inspect')) {
35+
return true;
36+
}
3337
for (const prefix of ignoredPrefixes) {
3438
if (target.url().startsWith(prefix)) {
3539
return false;

src/main.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ function registerTool(tool: ToolDefinition): void {
148148
content,
149149
};
150150
} catch (error) {
151+
logger(`${tool.name} response handling error:`, error, error.stack);
151152
const errorText =
152153
error instanceof Error ? error.message : String(error);
153154

@@ -162,7 +163,7 @@ function registerTool(tool: ToolDefinition): void {
162163
};
163164
}
164165
} catch (err) {
165-
logger(`${tool.name} error: ${err.message}`);
166+
logger(`${tool.name} error:`, err, err.stack);
166167
throw err;
167168
} finally {
168169
guard.dispose();

0 commit comments

Comments
 (0)