Giter Club home page Giter Club logo

Comments (3)

katopz avatar katopz commented on September 26, 2024 1

Wow that's a super fancy things to do for inject something. 😆

Thanks!

from browser-extension-react-typescript-starter.

sinanbekar avatar sinanbekar commented on September 26, 2024

Thank you for reaching out. I am sharing an example setup that I created for one of my clients.
You can create the main injection script in content/injection folder.
(or wherever you want to structure it, crxjs and vite handle it. see: https://github.com/crxjs/chrome-extension-tools)
And you can import it inside content/index.ts

import pageContextInject from './injection/pageContextInject?script&module';
const setupInjectPageContextScript = () => {
  const s = document.createElement('script');
  s.src = chrome.runtime.getURL(pageContextInject);
  s.type = 'module';
  document.head.appendChild(s);
  s.onload = function () {
    s.remove();
  };
};

And at the end

(async function initialize() {
  const config = await getExtensionConfig();
  if (config.enabled) {
    //setupInitialDispatch();
    setupInjectPageContextScript();
    //setupInjections();
    //setupSomeOther();
  }
})();

Hope you find it useful.

from browser-extension-react-typescript-starter.

sinanbekar avatar sinanbekar commented on September 26, 2024

@katopz you may need to add this code to typings.d.ts to make tsc happy. see: https://www.typescriptlang.org/docs/handbook/modules.html#wildcard-module-declarations
https://vitejs.dev/guide/assets.html#importing-asset-as-url

declare module '*?script&module' {
  const src: string;
  export default src;
}

from browser-extension-react-typescript-starter.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.