From b0df1667c2498f99a7a275f1beaf2669caf879da Mon Sep 17 00:00:00 2001 From: njzydark Date: Tue, 21 Nov 2023 17:57:32 +0800 Subject: [PATCH] fix(permission): check and request permission should ignore url port The same cookie is shared by different ports of the same domain name. If a port is added when request permission, the urls of different ports of the same domain name cannot access the current cookie. For example, localhost:8080 requires the cookie of localhost --- interface/lib/permissionHandler.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/interface/lib/permissionHandler.js b/interface/lib/permissionHandler.js index deac208..1c71438 100644 --- a/interface/lib/permissionHandler.js +++ b/interface/lib/permissionHandler.js @@ -49,6 +49,12 @@ export class PermissionHandler { const testPermission = { origins: [url], }; + try { + const { protocol, hostname } = new URL(url); + testPermission.origins = [`${protocol}//${hostname}/*`]; + } catch (err) { + console.error(err); + } // If we don't have access to the permission API, assume we have // access. Safari devtools can't access the API. @@ -70,6 +76,12 @@ export class PermissionHandler { const permission = { origins: [url], }; + try { + const { protocol, hostname } = new URL(url); + permission.origins = [`${protocol}//${hostname}/*`]; + } catch (err) { + console.error(err); + } return this.browserDetector.getApi().permissions.request(permission); } }