Skip to content

Commit

Permalink
Merge pull request #169 from Moustachauve/permissions
Browse files Browse the repository at this point in the history
Request permission for the full domain when selecting "this site"
  • Loading branch information
Moustachauve authored Feb 22, 2024
2 parents 8c6e08d + 0480f5e commit f333289
Showing 1 changed file with 27 additions and 2 deletions.
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];
}
}

0 comments on commit f333289

Please sign in to comment.