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

support content_scripts[i].world in manifest #744

Closed
wants to merge 5 commits into from

Conversation

TheColaber
Copy link

Resolves #741

Without this change it will error in the console which blocks all usage of rpce

@changeset-bot
Copy link

changeset-bot bot commented Jul 1, 2023

🦋 Changeset detected

Latest commit: ab3edb5

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

This PR includes changesets to release 2 packages
Name Type
rollup-plugin-chrome-extension Patch
@crxjs/vite-plugin 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

@vercel
Copy link

vercel bot commented Jul 1, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
vite-plugin-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 14, 2024 7:52pm

@jacksteamdev
Copy link
Contributor

I'd like for CRXJS to support this feature, but there's more work to be done before this PR will work. For now, I'm going to decline merging this b/c I don't want to create extra confusion.

Why Not?

Vite is an ES modules build tool, but Chrome Extension content scripts are plain scripts, not ESM. We can support ESM in content scripts using import() and this is what CRXJS does. It makes a loader file that looks like this:

(function () {
  'use strict';

  const injectTime = performance.now();
  (async () => {
    if ("")
      await import(
        /* @vite-ignore */
        chrome.runtime.getURL("")
      );
    await import(
      /* @vite-ignore */
      chrome.runtime.getURL("vendor/vite-client.js")
    );
    const { onExecute } = await import(
      /* @vite-ignore */
      chrome.runtime.getURL("src/content.ts.js")
    );
    onExecute?.({ perf: { injectTime, loadTime: performance.now() - injectTime } });
  })().catch(console.error);

})();

Notice the use of chrome.runtime.getURL to get the right URL for the content script. This method isn't available in the main world, so we can't just add the world: MAIN field, we need to solve the problem of creating a non-ESM content script file.

What Else

We need to find a way to use Vite to build an IIFE script. I'm sure this can be done, but I haven't been able to put in the hours to get it working.

PRs are appreciated.

@beautyfree
Copy link

@TheColaber can you continue work on it?

@jacksteamdev jacksteamdev added the content-script-world Related to main or isolated content script execution context label Jan 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
content-script-world Related to main or isolated content script execution context schema vite-plugin Related to Vite plugin
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MV3 Schema is missing world property for content scripts
3 participants