diff --git a/devtools/server/actors/storage.js b/devtools/server/actors/storage.js index d5f3ddae5e20..11455499b87b 100644 --- a/devtools/server/actors/storage.js +++ b/devtools/server/actors/storage.js @@ -635,12 +635,9 @@ StorageActors.createActor( populateStoresForHost(host) { this.hostVsStores.set(host, new Map()); - const doc = this.storageActor.document; - const cookies = this.getCookiesFromHost( - host, - doc.effectiveStoragePrincipal.originAttributes - ); + const originAttributes = this.getOriginAttributesFromHost(host); + const cookies = this.getCookiesFromHost(host, originAttributes); for (const cookie of cookies) { if (this.isCookieAtHost(cookie, host)) { @@ -653,6 +650,22 @@ StorageActors.createActor( } }, + getOriginAttributesFromHost(host) { + const win = this.storageActor.getWindowFromHost(host); + let originAttributes; + if (win) { + originAttributes = + win.document.effectiveStoragePrincipal.originAttributes; + } else { + // If we can't find the window by host, fallback to the top window + // origin attributes. + originAttributes = this.storageActor.document.effectiveStoragePrincipal + .originAttributes; + } + + return originAttributes; + }, + /** * Notification observer for "cookie-change". * @@ -763,8 +776,7 @@ StorageActors.createActor( * See editCookie() for format details. */ async editItem(data) { - const doc = this.storageActor.document; - data.originAttributes = doc.effectiveStoragePrincipal.originAttributes; + data.originAttributes = this.getOriginAttributesFromHost(data.host); this.editCookie(data); }, @@ -777,30 +789,18 @@ StorageActors.createActor( }, async removeItem(host, name) { - const doc = this.storageActor.document; - this.removeCookie( - host, - name, - doc.effectiveStoragePrincipal.originAttributes - ); + const originAttributes = this.getOriginAttributesFromHost(host); + this.removeCookie(host, name, originAttributes); }, async removeAll(host, domain) { - const doc = this.storageActor.document; - this.removeAllCookies( - host, - domain, - doc.effectiveStoragePrincipal.originAttributes - ); + const originAttributes = this.getOriginAttributesFromHost(host); + this.removeAllCookies(host, domain, originAttributes); }, async removeAllSessionCookies(host, domain) { - const doc = this.storageActor.document; - this.removeAllSessionCookies( - host, - domain, - doc.effectiveStoragePrincipal.originAttributes - ); + const originAttributes = this.getOriginAttributesFromHost(host); + this.removeAllSessionCookies(host, domain, originAttributes); }, maybeSetupChildProcess() {