Code Monkey home page Code Monkey logo

Comments (6)

Jervis2049 avatar Jervis2049 commented on June 18, 2024 1

@rhinonan 刚发布了0.0.7-beta.0 , 支持这个功能了,安装这个版本试下。

from vite-plugin-crx-mv3.

Jervis2049 avatar Jervis2049 commented on June 18, 2024

可以写个demo吗,然后上传到你的GITHUB仓库,我看看你现在的写法。

from vite-plugin-crx-mv3.

rhinonan avatar rhinonan commented on June 18, 2024

demo 在公司,有信息安全整不出来,我贴下主要代码。 我用的是你的example 里面的 vue 示例

如果不能理解,我再重新写一个DEMO

// content.ts 主要代码
window.onload = async () => {
  const el = document.querySelector('body');
  const sc = document.createElement('script');
  // 我需要获取页面中的js变量,所有只能插入这个js,并且这个资源需要在manifest -> web_accessible_resources 中声明
  // 这个js我希望ts编写,所以希望vite能够编译
  //
  const injected = chrome.runtime.getURL('content_script/injected.js');
  sc.src = injected;
  if (el) {
    el.appendChild(sc);
  }
}
/* manifest.json */
{
        ......,
	"web_accessible_resources": [
	{
		"resources": ["content_script/injected.js"],
		"matches": [
			"*://*/*",
			"<all_urls>"
		]
	  }
	]
}

from vite-plugin-crx-mv3.

Jervis2049 avatar Jervis2049 commented on June 18, 2024

demo 在公司,有信息安全整不出来,我贴下主要代码。 我用的是你的example 里面的 vue 示例

如果不能理解,我再重新写一个DEMO

// content.ts 主要代码
window.onload = async () => {
  const el = document.querySelector('body');
  const sc = document.createElement('script');
  // 我需要获取页面中的js变量,所有只能插入这个js,并且这个资源需要在manifest -> web_accessible_resources 中声明
  // 这个js我希望ts编写,所以希望vite能够编译
  //
  const injected = chrome.runtime.getURL('content_script/injected.js');
  sc.src = injected;
  if (el) {
    el.appendChild(sc);
  }
}
/* manifest.json */
{
        ......,
	"web_accessible_resources": [
	{
		"resources": ["content_script/injected.js"],
		"matches": [
			"*://*/*",
			"<all_urls>"
		]
	  }
	]
}

好的,明白你意思了,之前确实没考虑到这种情况。

from vite-plugin-crx-mv3.

rhinonan avatar rhinonan commented on June 18, 2024

大佬牛逼,我现在就试一试

from vite-plugin-crx-mv3.

rhinonan avatar rhinonan commented on June 18, 2024

@Jervis2049 已经验证,能够正常编译。

from vite-plugin-crx-mv3.

Related Issues (20)

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.