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

feat(chrome-extension): Handle manifest permissions in a more-deterministic fashion #4133

Open
wants to merge 21 commits into
base: main
Choose a base branch
from

Conversation

tmilewski
Copy link
Member

@tmilewski tmilewski commented Sep 10, 2024

Description

Breaking Change: Service Workers / Session Handling

The extension now requires the storage permission in order to maintain sessions and provide authenticated access to other extension features, such as service workers.

How to Update:

  • Please add storage to the permissions key in your extension manifest.

Breaking Change: Host Session Syncing

The extension no longer infers the sync host as the original implementation led to increased configuration confusion and false positives.

As such, we've replaced syncSessionWithTab with syncHost. You can set syncHost to the host URL you intend to retrieve the authentication state from.

How to Update:

  • Please replace syncSessionWithTab with syncHost="<YOUR_CLERK_FRONTEND_API_DOMAIN>"
  • Please ensure that the sync host, along with your app host, is listed in host_permissions and appended with /*. e.g.: https://<YOUR_DOMAIN>/* and https://clerk.<YOUR_DOMAIN>/*

Fixes ECO-212

Feature: Service Workers createClerkClient

We've introduced a new method createClerkClient to handle background tasks in your extension!

import { createClerkClient } from '@clerk/chrome-extension/background';

// Create a new Clerk instance and get a fresh token for the user
async function getToken() {
  const clerk = await createClerkClient({
    publishableKey: process.env.PLASMO_PUBLIC_CLERK_PUBLISHABLE_KEY,
  });
  return await clerk.session?.getToken();
}

// Create a listener to listen for messages from content scripts
// NOTE: A runtime listener cannot be async.
//       It must return true, in order to keep the connection open and send a response later.
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
  // You can use the token in the listener to perform actions on behalf of the user
  // OR send the token back to the content script
  getToken().then(token => sendResponse({ token }));
  return true;
});

Fixes ECO-213

Checklist

  • npm test runs as expected.
  • npm run build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

@tmilewski tmilewski self-assigned this Sep 10, 2024
Copy link

changeset-bot bot commented Sep 10, 2024

🦋 Changeset detected

Latest commit: 73c16ec

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@clerk/chrome-extension Major

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@tmilewski
Copy link
Member Author

!allow-major

@@ -35,71 +35,14 @@ describe('Cookies', () => {
}

describe('getClientCookie', () => {
Copy link
Member Author

Choose a reason for hiding this comment

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

Reduced complexity of the getClientCookie thus these tests are no longer necessary.

host_permissions: ['http://localhost:3000'],
} as ValidatedManifest;
import { missingManifestKeyError } from '../errors';
import { validateManifest } from '../manifest';

describe('Manifest', () => {
describe('validateManifest(manifest)', () => {
Copy link
Member Author

Choose a reason for hiding this comment

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

Reduced complexity of the validateManifest thus these tests are no longer necessary.


#### Extension Manifest (`manifest.json`)
### Usage
Copy link
Member Author

Choose a reason for hiding this comment

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

Split docs out into separate files as we've found that important details tended to be missed/buried otherwise.

@tmilewski tmilewski marked this pull request as ready for review October 10, 2024 15:18
@clerk clerk deleted a comment from clerk-cookie Oct 10, 2024
@clerk clerk deleted a comment from clerk-cookie Oct 10, 2024
Copy link
Member

@royanger royanger left a comment

Choose a reason for hiding this comment

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

I've been working with this for the last week testing and building apps for documentation and so far there have been no issues. Excited to see this release! 🚀

@clerk clerk deleted a comment from clerk-cookie Oct 28, 2024
@clerk clerk deleted a comment from clerk-cookie Oct 28, 2024
@clerk clerk deleted a comment from clerk-cookie Oct 28, 2024
@clerk clerk deleted a comment from clerk-cookie Oct 28, 2024
@clerk clerk deleted a comment from clerk-cookie Oct 28, 2024
@clerk clerk deleted a comment from clerk-cookie Oct 28, 2024
@clerk clerk deleted a comment from clerk-cookie Oct 28, 2024
@tmilewski tmilewski force-pushed the tm/ext-updates branch 2 times, most recently from a0079e1 to 5846131 Compare October 30, 2024 19:35
@tmilewski
Copy link
Member Author

!snapshot

@clerk clerk deleted a comment from clerk-cookie Oct 30, 2024
@clerk-cookie
Copy link
Collaborator

Hey @tmilewski - the snapshot version command generated the following package versions:

Package Version
@clerk/astro 1.4.2-snapshot.v5846131
@clerk/backend 1.15.2-snapshot.v5846131
@clerk/chrome-extension 2.0.0-snapshot.v5846131
@clerk/clerk-js 5.30.0-snapshot.v5846131
@clerk/elements 0.17.2-snapshot.v5846131
@clerk/clerk-expo 2.2.30-snapshot.v5846131
@clerk/express 1.3.4-snapshot.v5846131
@clerk/fastify 2.0.6-snapshot.v5846131
@clerk/localizations 3.4.1-snapshot.v5846131
@clerk/nextjs 6.0.3-snapshot.v5846131
@clerk/clerk-react 5.13.2-snapshot.v5846131
@clerk/remix 4.2.42-snapshot.v5846131
@clerk/clerk-sdk-node 5.0.55-snapshot.v5846131
@clerk/shared 2.10.2-snapshot.v5846131
@clerk/tanstack-start 0.4.18-snapshot.v5846131
@clerk/testing 1.3.16-snapshot.v5846131
@clerk/themes 2.1.40-snapshot.v5846131
@clerk/types 4.29.0-snapshot.v5846131
@clerk/ui 0.1.11-snapshot.v5846131
@clerk/upgrade 1.2.0-snapshot.v5846131

Tip: Use the snippet copy button below to quickly install the required packages.
@clerk/astro

npm i @clerk/[email protected] --save-exact

@clerk/backend

npm i @clerk/[email protected] --save-exact

@clerk/chrome-extension

npm i @clerk/[email protected] --save-exact

@clerk/clerk-js

npm i @clerk/[email protected] --save-exact

@clerk/elements

npm i @clerk/[email protected] --save-exact

@clerk/clerk-expo

npm i @clerk/[email protected] --save-exact

@clerk/express

npm i @clerk/[email protected] --save-exact

@clerk/fastify

npm i @clerk/[email protected] --save-exact

@clerk/localizations

npm i @clerk/[email protected] --save-exact

@clerk/nextjs

npm i @clerk/[email protected] --save-exact

@clerk/clerk-react

npm i @clerk/[email protected] --save-exact

@clerk/remix

npm i @clerk/[email protected] --save-exact

@clerk/clerk-sdk-node

npm i @clerk/[email protected] --save-exact

@clerk/shared

npm i @clerk/[email protected] --save-exact

@clerk/tanstack-start

npm i @clerk/[email protected] --save-exact

@clerk/testing

npm i @clerk/[email protected] --save-exact

@clerk/themes

npm i @clerk/[email protected] --save-exact

@clerk/types

npm i @clerk/[email protected] --save-exact

@clerk/ui

npm i @clerk/[email protected] --save-exact

@clerk/upgrade

npm i @clerk/[email protected] --save-exact

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants