Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request permission for the full domain when selecting "this site" #169

Merged
merged 1 commit into from
Feb 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions interface/lib/permissionHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ export class PermissionHandler {
};
try {
const { protocol, hostname } = new URL(url);
testPermission.origins = [`${protocol}//${hostname}/*`];
const rootDomain = this.getRootDomainName(hostname);
testPermission.origins = [
`${protocol}//${hostname}/*`,
`${protocol}//*.${rootDomain}/*`,
];
} catch (err) {
console.error(err);
}
Expand All @@ -78,10 +82,31 @@ export class PermissionHandler {
};
try {
const { protocol, hostname } = new URL(url);
permission.origins = [`${protocol}//${hostname}/*`];
const rootDomain = this.getRootDomainName(hostname);
permission.origins = [
`${protocol}//${hostname}/*`,
`${protocol}//*.${rootDomain}/*`,
];
} catch (err) {
console.error(err);
}
return this.browserDetector.getApi().permissions.request(permission);
}

/**
* Gets the root domain of an URL
* @param {string} domain
* @return {string}
*/
getRootDomainName(domain) {
const parts = domain.split('.').reverse();
const cnt = parts.length;
if (cnt >= 3) {
// see if the second level domain is a common SLD.
if (parts[1].match(/^(com|edu|gov|net|mil|org|nom|co|name|info|biz)$/i)) {
return parts[2] + '.' + parts[1] + '.' + parts[0];
}
}
return parts[1] + '.' + parts[0];
}
}
Loading