Skip to content

browser.extension null  #120

@tidys

Description

@tidys

Describe the bug

var browser = injectionContext.browser; // browser=null
var extension = browser.extension, // fuck null

To Reproduce

  1. 配置vue.config.js
{
	"pluginOptions": {
		"browserExtension": {
			"componentOptions": {
				"contentScripts": {
					"components": {
						background: true,
						contentScripts: true,
					},
					"entries": {
						content: "src/content.js",
						inject: "src/inject.js"
					}
				}
			}
		}
	}
}
  1. content.js中注入脚本inject.js
 let content = chrome.extension.getURL("js/inject.js")
  console.log(`[cc-inspector]注入脚本:${content}`);
  let script = document.createElement('script')
  script.setAttribute('type', 'text/javascript')
  script.setAttribute('src', content)
  script.onload = function () {
    // 注入脚本执行完后移除掉
    this.parentNode.removeChild(this);
  }
  document.body.appendChild(script)
  1. npm run build-watch
    package.json
"scripts":{
"build-watch": "vue-cli-service build --watch"
}
  1. 加载后,出现null问题,似乎是引用的其他插件导致的
    image

代码好像来自:

/* tslint:disable */

/* -------------------------------------------------- */

/* Start of Webpack Hot Extension Middleware */

/* ================================================== */

/* This will be converted into a lodash templ., any */

/* external argument must be provided using it */

/* -------------------------------------------------- */

Expected behavior
这个问题影响了我的开发体验,导致content无法注入的脚本无法正常工作

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions