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

Merged
merged 22 commits into from
Nov 22, 2024

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: 9f1f1b9

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

This PR includes changesets to release 9 packages
Name Type
@clerk/clerk-js Patch
@clerk/clerk-react Patch
@clerk/chrome-extension Major
@clerk/clerk-expo Patch
@clerk/elements Patch
@clerk/nextjs Patch
@clerk/remix Patch
@clerk/tanstack-start Patch
@clerk/ui Patch

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
@tmilewski tmilewski removed the blocked label Nov 22, 2024
@tmilewski tmilewski merged commit 4da28fa into main Nov 22, 2024
27 checks passed
@tmilewski tmilewski deleted the tm/ext-updates branch November 22, 2024 16:40
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