Coder Social home page Coder Social logo

mubaidr / vite-vue3-chrome-extension-v3 Goto Github PK

View Code? Open in Web Editor NEW
348.0 348.0 45.0 988 KB

Another vite powered web extension (chrome, firefox, etc.) starter template.

JavaScript 5.54% TypeScript 56.84% HTML 6.35% Vue 27.99% SCSS 3.29%
chrome extension hacktoberfest vite vue3 webextension

vite-vue3-chrome-extension-v3's Introduction

vite-vue3-browser-extension-v3

build release

A Vite powered WebExtension (Chrome, FireFox, etc.) starter template based on manifest 3, vue3 and vite.

Please check: vite-chrome-extension for a more simpler template

Features

  • Vue 3 - Composition API, Script setup and more!
  • Vue 3 app in Content Script too (template added)
  • Vue devtools support
  • HMR for extension pages and content scripts, with Firefox support
  • Sample onInstall & onUpdate pages
  • Tailwind css And daisyUI
  • Tailwindcss plugins for Typography, forms, prettier and daisy ui
  • Vue Router setup incuding unplugin-vue-router for automatic route registration
  • vscode recommended settings and extensions for chrome plugin development
  • Effortless communications - powered by webext-bridge
  • Components auto importing
  • Icons - Access to icons from any iconset directly
  • TypeScript - type safe
  • Eslint & Prettier configured for vue, javascript, TypeScript
  • CRXJS Vite Plugin Build a Chrome Extension with Vite
  • Github build and release actions

Please create an issue if you feel some feature is missing or could be improved.

Pre-packed

Vite Plugins

Vue Plugins

  • Pinia - Intuitive, type safe, light and flexible Store for Vue
  • VueUse - collection of useful composition APIs

Plugins

  • Marked - A markdown parser and compiler. Used for CHANGELOG.md to show in Update page

UI Frameworks

  • tailwindcss - A utility-first CSS framework
  • daisyUI - The most popular component library for Tailwind CSS

Tailwind css forms and typography plugins are enabled for default styling of form controls.

WebExtension Libraries

Coding Style

Use the Template

GitHub Template

Create a repo from this template on GitHub.

Clone to local

If you prefer to do it manually with the cleaner git history

If you don't have pnpm installed, run: npm install -g pnpm

pnpx degit mubaidr/vite-vue3-chrome-extension-v3 my-webext
cd my-webext
pnpm i

Usage

Project Structure

  • src - main source.
    • content-script - scripts and components to be injected as content_script
      • iframe content script iframe vue3 app which will be injected into page
    • background - scripts for background.
    • popup - popup vuejs application root
      • pages - popup pages
    • options - options vuejs application root
      • pages - options pages
    • setup - Page for Install and Update chrome extension events
      • pages - pages for install and update events
    • offscreen - Chrome extension offscreen pages, can be used for audio, screen recording
    • pages - application pages, common to all views (About, Contact, Authentication etc)
    • components - auto-imported Vue components that are shared in popup and options page.
    • assets - assets used in Vue components
  • dist - built files
    • chrome - Chrome extension
    • firefox - Firefox extension

Extra info

In src/background/index.ts you can find an example of chrome.runtime.onInstalled.addListener.

We add ?type to the url to tell if it's update or install event. Then in src/setup/pages/index.ts we check for the type and show the appropriate page.

Development

pnpm dev

Then load extension in browser with the dist/ folder.

Build

To build the extension, run

pnpm build

And then pack files under dist/chrome or dist/firefox, you can upload to appropriate extension store.

Contributors

mubaidr
Muhammad Ubaid Raza
ultimateshadsform
Alexander
baramofme
Jihoon Yi
justorez
Null

Credits

This template is heavenly inspired by: https://github.com/antfu/vitesse-webext

vite-vue3-chrome-extension-v3's People

Contributors

baramofme avatar dependabot[bot] avatar github-actions[bot] avatar justorez avatar mubaidr avatar ultimateshadsform avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

vite-vue3-chrome-extension-v3's Issues

[feature request] add some actions to the right click menu

Can you add some template code to create custom action in the right-click menu in all tabs?

i've tried the methods in this, but I see no new actions in my right-click menu on any websites.

I would be grateful if you could offer some help โค๏ธ

Add Prefix To Isolate Source Website And Our Plugin

Thank you for such an awesome project๐Ÿฅฐ! While using it, I've run into some issues, like class name conflicts between Tailwind CSS and the original website's styles.
I think it can add a prefix(to the tailwindcss) by Custom Directives of Vue to isolate the source website and our Chrome plugin like this:

<div v-prefix-class="flex flex-col ...">
  ...
</div>

and it will be:

<div class="custom-prefix-flex custom-prefix-flex-col ...">
  ...
</div>

or we can use some building utils like postcss to add prefix autoly.
What's your take on the two solutions above? If it's feasible, I can try to code it.

promise error message

I am running pnpm dev in the console with no errors but when I look in the chrome extensions( console )
I see this error. Any ideas on how to fix?
error_2

Migrate to Nuxt

  • File-based Routing
  • Modular Architecture
  • Automatic Code Splitting
  • Nuxt layers for sharing base configuration/ design between all extension pages

Chrome V3 Refused to execute inline script ...

Hi,

thank you very much for providing a great Chrome plugin template. This is when I opened a new window using the V3 version through [chrome.tabs.create] and executed a JavaScript code, the console encountered an error as follows:

image

After trying, I still cannot solve this problem until now...
Can you help me solve this problem? Thank you ๐Ÿ™

Inject into content script

Thank you for this great project!
Can you guide me how to inject popup into content script? I want to show the whole popup into website page.

limited to iframe size

"Hello, I'm creating a button in a content-script with a fixed position. Everything is working great. But I need a modal window to be displayed across the entire screen when this button is clicked. However, I'm limited by the dimensions of the iframe. What should I do?"

content-script does not use iframe, style issue

content-script/index.ts code

import { createApp } from 'vue'
import App from './content/app.vue'
import './index.scss'

const container = document.createElement('div')
container.id = 'test' 
container.className = 'test' 

const root = document.createElement('div')
root.id = 'test-app'


const shadowDOM = container.attachShadow?.({ mode: 'open' }) || container
shadowDOM.appendChild(root)


document.body.appendChild(container)


const app = createApp(App)

app.config.globalProperties.$app = {
  context: '',
}


app.provide('app', app.config.globalProperties.$app)


app.mount(root)

content-script/content/app.vue

<template>
  <div class="testqwe">
    <div
      class="floating-text"
      style="font-size: 50px; color: red"
    >
      test
    </div>
  </div>
</template>
<style lang="scss">
.floating-text {
 position: fixed;
  top: 50%;
   left: 50%;
  transform: translate(-50%, -50%);
  font-size: 24px;
  font-weight: bold;
   padding: 10px;
   background-color: rgba(0, 0, 0, 0.5);
   color: white;
   border-radius: 5px;
}
.testqwe {
  background-color: #ffffff;
}

Neither the styles in index.scss nor the styles in style lang='scss' are taking effect, only the inline styles mentioned above are working. Why is this happening?
I want to create a floating content that appears in the middle of the page, without using an iframe.

pnpm dev results in an error with fresh install

I've installed a fresh instance of this repo and when I run pnpm dev I get this response:

[vite:css] [postcss] Cannot read properties of undefined (reading 'config') file: /__uno.css:undefined:undefined

I can successfully run this repo if I remove the tailwindcss: {}, from postcss.config.cjs

Any ideas on how to fix?

TODO Update to Vite 5

I have seen https://github.com/crxjs/chrome-extension-tools has updated and fixed the Vite 5 problem with @crxjs/[email protected] version.

crxjs/chrome-extension-tools@ce9fe1c: Fix/web accessible resources script modules
crxjs/chrome-extension-tools@48d8c68: Vite 5 moved vite manifest from 'manifest.json' to
'.vite/manifest.json'. This change updates the plugin to use the new location
if Vite major version is >4, old location otherwise.

I haven't tested it yet but it's a goal.

Global error handling to avoid extension context issues

This ensures errors are logged, but extension context is not disconnected.

self.onerror = function (message, source, lineno, colno, error) {
  console.info(
    `Error: ${message}\nSource: ${source}\nLine: ${lineno}\nColumn: ${colno}\nError object: ${error}`
  )
}

Fix for the src problem

I have finally fixed it!

Move all html files outside src folder like this:

image

Add setup page to rollup:
image

Change ts path inside all html files to relative ts file:
image

Now everything works as expected:
image

Question: image paths inside vue components

First of all, great template!

Question: instead of relative image paths like

<img src="../../assets/vite.svg" />

Would it be possible to use the alias defined in vite.config.ts?

<img src="src/assets/vite.svg" />

It's not working with the current setup.

Popup page shows Options page

I build source and load it on chrome.

And then I found Popup shows Options page.

Options show it self That's fine.

options.html

    <script type="module" crossorigin src="..\..\assets/index.html-74b33acf.js"></script>
    <link rel="modulepreload" crossorigin href="..\..\assets/base-176afb78.js">

popup.html

    <script type="module" crossorigin src="..\..\assets/index.html-02ab7c9c.js"></script>
    <link rel="modulepreload" crossorigin href="..\..\assets/base-176afb78.js">

common ref is base-176afb78.js. so I investigated.

base-176afb78.js


// It's options.html content
// and lu render options.html contents
function iu(e, t) {
    return so(), oo(xe, null, [hs(" ์˜ต์…˜ ํŽ˜์ด์ง€ "), ou], 64)
}
const lu = Co(su, [["render", iu], ["__scopeId", "data-v-a4d9e10f"]]);


// It's popup.html content
// du is render popup.html content
function au(e, t) {
    return so(), oo(xe, null, [uu, hs(" ํŒ์—… ํŽ˜์ด์ง€ "), fu], 64)
}
const du = Co(cu, [["render", au], ["__scopeId", "data-v-15bb346d"]]),


// and root path mapping only options page component (lu).
bu = [{path: "/", component: lu, 
children: [{name: "index", path: "", component: du, props: !0}], props: !0}];
export {Co as _, _u as a, mu as b, pu as c, bu as d, gu as e, so as o, hu as r};

I don't know why, but router info and each app.vue has merged.
so that, when popupt.html trying to access root path. router returns only option pages component.

[bug] Failed to load picture

ๆˆชๅฑ2023-03-04 10 15 28

I just clone the template and run command pnpm dev, and the vue's logo is broken.

I guess it needs to be placed in public folder?

My platform and os: chrome, mac

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.