Skip to content

Commit 301f4b0

Browse files
Fix local urls support in a11y scan (#52)
* feat: enhance accessibility scan report with issue count and pagination details * Refactor: Improve formatting and error logging in AccessibilityScanner * Refactor: Replace hardcoded local IP with a set of local hostnames in AccessibilityScanner * Fix: Add '0.0.0.0' to local hosts in AccessibilityScanner * Bump version to 1.1.4 in package.json and package-lock.json * Fix: Improve formatting of localHosts declaration in AccessibilityScanner
1 parent ea5ea01 commit 301f4b0

File tree

4 files changed

+26
-28
lines changed

4 files changed

+26
-28
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@browserstack/mcp-server",
3-
"version": "1.1.3",
3+
"version": "1.1.4",
44
"description": "BrowserStack's Official MCP Server",
55
"main": "dist/index.js",
66
"repository": {

src/lib/local.ts

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ export async function killExistingBrowserStackLocalProcesses() {
7373
}
7474
}
7575

76-
export async function ensureLocalBinarySetup(localIdentifier?: string): Promise<void> {
76+
export async function ensureLocalBinarySetup(
77+
localIdentifier?: string,
78+
): Promise<void> {
7779
logger.info(
7880
"Ensuring local binary setup as it is required for private URLs...",
7981
);
@@ -87,33 +89,30 @@ export async function ensureLocalBinarySetup(localIdentifier?: string): Promise<
8789
localIdentifier?: string;
8890
} = {
8991
key: config.browserstackAccessKey,
90-
username: config.browserstackUsername
92+
username: config.browserstackUsername,
9193
};
9294

9395
if (localIdentifier) {
9496
requestBody.localIdentifier = localIdentifier;
9597
}
9698

9799
return await new Promise((resolve, reject) => {
98-
localBinary.start(
99-
requestBody,
100-
(error?: Error) => {
101-
if (error) {
102-
logger.error(
103-
`Unable to start BrowserStack Local... please check your credentials and try again. Error: ${error}`,
104-
);
100+
localBinary.start(requestBody, (error?: Error) => {
101+
if (error) {
102+
logger.error(
103+
`Unable to start BrowserStack Local... please check your credentials and try again. Error: ${error}`,
104+
);
105105

106-
reject(
107-
new Error(
108-
`Unable to configure local tunnel binary, please check your credentials and try again. Error: ${error}`,
109-
),
110-
);
111-
} else {
112-
logger.info("Successfully started BrowserStack Local");
113-
resolve();
114-
}
115-
},
116-
);
106+
reject(
107+
new Error(
108+
`Unable to configure local tunnel binary, please check your credentials and try again. Error: ${error}`,
109+
),
110+
);
111+
} else {
112+
logger.info("Successfully started BrowserStack Local");
113+
resolve();
114+
}
115+
});
117116
});
118117
}
119118

src/tools/accessiblity-utils/scanner.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,10 @@ export class AccessibilityScanner {
2929
name: string,
3030
urlList: string[],
3131
): Promise<AccessibilityScanResponse> {
32-
3332
// Check if any URL is local
3433
const hasLocal = urlList.some(isLocalURL);
3534
const localIdentifier = crypto.randomUUID();
36-
const LOCAL_IP = "127.0.0.1";
35+
const localHosts = new Set(["127.0.0.1", "localhost", "0.0.0.0"]);
3736
const BS_LOCAL_DOMAIN = "bs-local.com";
3837

3938
if (hasLocal) {
@@ -45,13 +44,13 @@ export class AccessibilityScanner {
4544
const transformedUrlList = urlList.map((url) => {
4645
try {
4746
const parsed = new URL(url);
48-
if (parsed.hostname === LOCAL_IP) {
47+
if (localHosts.has(parsed.hostname)) {
4948
parsed.hostname = BS_LOCAL_DOMAIN;
5049
return parsed.toString();
5150
}
5251
return url;
5352
} catch (e) {
54-
logger.warn(`[AccessibilityScan] Invalid URL skipped: ${url}`);
53+
logger.warn(`[AccessibilityScan] Invalid URL skipped: ${e}`);
5554
return url;
5655
}
5756
});
@@ -68,7 +67,7 @@ export class AccessibilityScanner {
6867
localTestingInfo: {
6968
localIdentifier,
7069
localEnabled: true,
71-
}
70+
},
7271
};
7372
requestBody = { ...baseRequestBody, ...localConfig };
7473
}

0 commit comments

Comments
 (0)