How can Chrome Extension identify browser authentication with a website -- manifest 3?

Viewed 98

Locally on my mac book, my chrome extension is trying to identify whether or not my chrome browser is signed into a specific website. I am referencing these docs. However, the cookie data I am getting back for this specific website is the same regardless of whether or not my browser has authenticated with the site. This is what the cookie looks like printed to console:

{
    "domain": "some-random-string.ngrok.io",
    "hostOnly": true,
    "httpOnly": true,
    "name": "_the_app_session",
    "path": "/",
    "sameSite": "unspecified",
    "secure": false,
    "session": true,
    "storeId": "0",
    "value": "random sttring"
}

This is the code I am running:

// Attempt
chrome.cookies.getAll(
    {"url": "https://some-random-string.ngrok.io", "name": "_the_app_session"},
    function(cookies) {
      console.log('cookies', cookies)
    }
  )

// Attempt
chrome.cookies.get({"url": "https://some-random-string.ngrok.io", "name": "_the_app_session"}, function(cookie) {
   console.log('cookie', cookie)
 });

How can my chrome extension identify whether or not my browser is signed into a specific website?

This is my manifest file:

{
  "manifest_version": 3,
  "icons": {
    "16": "cooking-icon.png",
    "128": "cooking-icon.png"
  },
  "name": "Some app",
  "description": "A Chrome extension app",
  "version": "0.1.0",
  "action": {
    "default_title": "App",
    "default_popup": "popup.html"
  },
  "permissions": [
    "cookies",
    "scripting"
  ],
  "host_permissions": [
    "http://*/*",
    "https://*/*"
  ]
}
1 Answers

My work around for this was to create an endpoint in my app which would check whether or not the browser was signed in. Make a GET request to this endpoint:

const authenticated = await fetch('http://random-string.ngrok.io/authenticated', {
      mode: 'cors',
      cache: 'no-cache',
      headers: {
        'Content-Type': 'application/json'
      },
      credentials: 'include'
    });

Based on the response my chrome extension could tell whether or not my browser has signed into the site.

Related