Skip to content

Commit

Permalink
Merge pull request #235 from GoogleChromeLabs/fix/opaque-origin-issue
Browse files Browse the repository at this point in the history
Handle opaque origin error when using `document.browsingTopics`
  • Loading branch information
mohdsayed authored Nov 5, 2023
2 parents afff9ba + 8531352 commit 7b8e746
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions packages/extension/src/contentScript/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -516,20 +516,23 @@ class WebpageContentScript {
* Set topics to be used in the Topics landing page.
*/
async setTopics() {
if (
!document.prerendering &&
'browsingTopics' in document &&
document.featurePolicy &&
document.featurePolicy.allowsFeature('browsing-topics')
) {
const activeTabUrl = window.location.origin;
const topicsObjArr = await document.browsingTopics();
const topicsIdArr = topicsObjArr.map(
(topic: { [key: string]: string | number }) => topic.topic
);
try {
if (
!document.prerendering &&
'browsingTopics' in document &&
document.featurePolicy &&
document.featurePolicy.allowsFeature('browsing-topics')
) {
const activeTabUrl = window.location.origin;
const topicsObjArr = await document.browsingTopics();
const topicsIdArr = topicsObjArr.map(
(topic: { [key: string]: string | number }) => topic.topic
);

CookieStore.setTopics(activeTabUrl, topicsIdArr);
}
CookieStore.setTopics(activeTabUrl, topicsIdArr);
}
// eslint-disable-next-line no-empty
} catch (error) {}
}
}

Expand Down

0 comments on commit 7b8e746

Please sign in to comment.