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

Cookie sharing example #565

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions examples/cookie-sharing/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## `key` in manifest.json

The `"key"` property declared in manifest.json is only included to ensure that the extension's ID is
static. We need a static ID in order for our web server (https://crx-sharing-cookies.glitch.me) to
ensure that only our demo extension can include the `token` cookie in requests.

See https://developer.chrome.com/docs/extensions/mv3/manifest/key/ for additional information.
10 changes: 10 additions & 0 deletions examples/cookie-sharing/background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
chrome.action.onClicked.addListener(async (tab) => {
const url = "https://crx-cookie-sharing.glitch.me/dreams";
const res = await fetch(url, {credentials: "include"});

let cookies = await chrome.cookies.getAll({
domain: chrome.runtime.getURL(''),
});

console.log(cookies);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was like — this demo clearly has to do something! No wait, it's just logging nothing to console.

Screen Shot 2021-04-08 at 12 09 34

If I visit the site, then click on the button, I get this error. I'm not a cookie expert. I don't know what to make of this.

});
17 changes: 17 additions & 0 deletions examples/cookie-sharing/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "Sharing Cookies via CORS",
"description": "This extension demonstrates how a extension and coordinating website can share cookies.",
"version": "1.0",
"manifest_version": 3,
"background": {
"service_worker": "wrapper.js"
},
"action": { },
"permissions": [
"cookies"
],
"host_permissions": [
"*://crx-sharing-cookies.glitch.me/*"
],
"key": "AAAAB3NzaC1yc2EAAAADAQABAAABAQCyQl/dWkS0lfmSPPuAdpnnjjU4LQ5Wp6Fn1ecriiRApmixldgk9GDmgJBT2CoDHfriSSM7eeMqiiR+tQbQ5rePVUeLGHtj7RiW6WjGdYKrb9Kn1XJzqK0Xxu8Uvh4GSw1q1BKCuCfs/2qpVrDOFyP4INrnGxVm4Fd/mvSVmEmB+SNxioZfMEW+8kbaQe1enALpOzrlFUnPJSG0G17mLzWoqKczklNQUdpAKkNK+Lmxb4yAy5+WLztK96NiDIJmNZ+L7xQWa4Imbdjt4gM/ZsRExHbvMHoo9etVjupvH3FdGffJlRostti6sGG6mZvLJiXsKBXz4UR+uBCb/ragczAB"
}
5 changes: 5 additions & 0 deletions examples/cookie-sharing/wrapper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
try {
importScripts("background.js");
} catch (e) {
console.log(e);
}