@browserstack/mcp-server 1.1.3 → 1.1.4
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/dist/lib/local.js
CHANGED
|
@@ -65,15 +65,19 @@ export async function killExistingBrowserStackLocalProcesses() {
|
|
|
65
65
|
// Continue execution as there may not be any processes running
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
|
-
export async function ensureLocalBinarySetup() {
|
|
68
|
+
export async function ensureLocalBinarySetup(localIdentifier) {
|
|
69
69
|
logger.info("Ensuring local binary setup as it is required for private URLs...");
|
|
70
70
|
const localBinary = new Local();
|
|
71
71
|
await killExistingBrowserStackLocalProcesses();
|
|
72
|
+
const requestBody = {
|
|
73
|
+
key: config.browserstackAccessKey,
|
|
74
|
+
username: config.browserstackUsername,
|
|
75
|
+
};
|
|
76
|
+
if (localIdentifier) {
|
|
77
|
+
requestBody.localIdentifier = localIdentifier;
|
|
78
|
+
}
|
|
72
79
|
return await new Promise((resolve, reject) => {
|
|
73
|
-
localBinary.start({
|
|
74
|
-
key: config.browserstackAccessKey,
|
|
75
|
-
username: config.browserstackUsername,
|
|
76
|
-
}, (error) => {
|
|
80
|
+
localBinary.start(requestBody, (error) => {
|
|
77
81
|
if (error) {
|
|
78
82
|
logger.error(`Unable to start BrowserStack Local... please check your credentials and try again. Error: ${error}`);
|
|
79
83
|
reject(new Error(`Unable to configure local tunnel binary, please check your credentials and try again. Error: ${error}`));
|
|
@@ -1,13 +1,55 @@
|
|
|
1
1
|
import axios from "axios";
|
|
2
2
|
import config from "../../config.js";
|
|
3
|
+
import logger from "../../logger.js";
|
|
4
|
+
import { isLocalURL, ensureLocalBinarySetup, killExistingBrowserStackLocalProcesses, } from "../../lib/local.js";
|
|
3
5
|
export class AccessibilityScanner {
|
|
4
6
|
auth = {
|
|
5
7
|
username: config.browserstackUsername,
|
|
6
8
|
password: config.browserstackAccessKey,
|
|
7
9
|
};
|
|
8
10
|
async startScan(name, urlList) {
|
|
11
|
+
// Check if any URL is local
|
|
12
|
+
const hasLocal = urlList.some(isLocalURL);
|
|
13
|
+
const localIdentifier = crypto.randomUUID();
|
|
14
|
+
const localHosts = new Set(["127.0.0.1", "localhost", "0.0.0.0"]);
|
|
15
|
+
const BS_LOCAL_DOMAIN = "bs-local.com";
|
|
16
|
+
if (hasLocal) {
|
|
17
|
+
await ensureLocalBinarySetup(localIdentifier);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
await killExistingBrowserStackLocalProcesses();
|
|
21
|
+
}
|
|
22
|
+
const transformedUrlList = urlList.map((url) => {
|
|
23
|
+
try {
|
|
24
|
+
const parsed = new URL(url);
|
|
25
|
+
if (localHosts.has(parsed.hostname)) {
|
|
26
|
+
parsed.hostname = BS_LOCAL_DOMAIN;
|
|
27
|
+
return parsed.toString();
|
|
28
|
+
}
|
|
29
|
+
return url;
|
|
30
|
+
}
|
|
31
|
+
catch (e) {
|
|
32
|
+
logger.warn(`[AccessibilityScan] Invalid URL skipped: ${e}`);
|
|
33
|
+
return url;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
const baseRequestBody = {
|
|
37
|
+
name,
|
|
38
|
+
urlList: transformedUrlList,
|
|
39
|
+
recurring: false,
|
|
40
|
+
};
|
|
41
|
+
let requestBody = baseRequestBody;
|
|
42
|
+
if (hasLocal) {
|
|
43
|
+
const localConfig = {
|
|
44
|
+
localTestingInfo: {
|
|
45
|
+
localIdentifier,
|
|
46
|
+
localEnabled: true,
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
requestBody = { ...baseRequestBody, ...localConfig };
|
|
50
|
+
}
|
|
9
51
|
try {
|
|
10
|
-
const { data } = await axios.post("https://api-accessibility.browserstack.com/api/website-scanner/v1/scans",
|
|
52
|
+
const { data } = await axios.post("https://api-accessibility.browserstack.com/api/website-scanner/v1/scans", requestBody, { auth: this.auth });
|
|
11
53
|
if (!data.success)
|
|
12
54
|
throw new Error(`Unable to start scan: ${data.errors?.join(", ")}`);
|
|
13
55
|
return data;
|