mirror of
https://github.com/harivansh-afk/sandbox-agent.git
synced 2026-04-19 13:01:48 +00:00
feat(inspector): add local network access support for HTTPS to HTTP connections
This commit is contained in:
parent
e984d07c28
commit
d1cbd20b83
4 changed files with 83 additions and 2 deletions
48
frontend/packages/inspector/src/lib/permissions.ts
Normal file
48
frontend/packages/inspector/src/lib/permissions.ts
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
export const askForLocalNetworkAccess = async (): Promise<boolean> => {
|
||||
try {
|
||||
const status = await navigator.permissions.query({
|
||||
// @ts-expect-error - local-network-access is not in standard types
|
||||
name: "local-network-access"
|
||||
});
|
||||
if (status.state === "granted") {
|
||||
return true;
|
||||
}
|
||||
if (status.state === "denied") {
|
||||
return false;
|
||||
}
|
||||
// If promptable, return true - browser will prompt on first request
|
||||
return true;
|
||||
} catch {
|
||||
// Permissions API not supported or permission not recognized - try anyway
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
export const isHttpsToHttpConnection = (pageUrl: string, targetUrl: string): boolean => {
|
||||
try {
|
||||
const page = new URL(pageUrl);
|
||||
const target = new URL(targetUrl);
|
||||
return page.protocol === "https:" && target.protocol === "http:";
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
export const isLocalNetworkTarget = (targetUrl: string): boolean => {
|
||||
try {
|
||||
const url = new URL(targetUrl);
|
||||
const hostname = url.hostname.toLowerCase();
|
||||
return (
|
||||
hostname === "localhost" ||
|
||||
hostname === "127.0.0.1" ||
|
||||
hostname === "::1" ||
|
||||
hostname.endsWith(".local") ||
|
||||
// Private IPv4 ranges
|
||||
/^10\./.test(hostname) ||
|
||||
/^172\.(1[6-9]|2[0-9]|3[0-1])\./.test(hostname) ||
|
||||
/^192\.168\./.test(hostname)
|
||||
);
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue