vue-cli-plugin-browser-extension icon indicating copy to clipboard operation
vue-cli-plugin-browser-extension copied to clipboard

Content Script fails to load

Open ghost opened this issue 5 years ago • 7 comments

Describe the bug Boilerplate gives an option to support a content script, but it does not load by the background.

To Reproduce Simply use the plugin with a fresh template

Expected behavior Console should print the content output.

** vue.config.js: **

module.exports = {
  pages: {
    popup: {
      template: 'public/browser-extension.html',
      entry: './src/popup/main.js',
      title: 'Popup'
    },
    options: {
      template: 'public/browser-extension.html',
      entry: './src/options/main.js',
      title: 'Options'
    },
    devtools: {
      template: 'public/browser-extension.html',
      entry: './src/devtools/main.js',
      title: 'Devtools'
    }
  },
  pluginOptions: {
    browserExtension: {
      componentOptions: {
        background: {
          entry: 'src/background.js'
        },
        contentScripts: {
          entries: {
            'content-script': [
              'src/content-scripts/content-script.js'
            ]
          }
        }
      }
    }
  }
}

** Error from background script** message: "Failed to load file: "content-script.js". "

ghost avatar May 11 '20 17:05 ghost

Looking at the dist directory I noticed content-script.js is never created.. as a workaround im manually inserting one..

ghost avatar May 11 '20 17:05 ghost

Can you share what's on your src/manifest.json file?

jatanassian avatar May 11 '20 22:05 jatanassian

{
  "manifest_version": 2,
  "name": "__MSG_extName__",
  "homepage_url": "http://localhost:8080/",
  "description": "A Vue Browser Extension",
  "default_locale": "en",
  "permissions": [
    "<all_urls>",
    "*://*/*"
  ],
  "icons": {
    "16": "icons/16.png",
    "48": "icons/48.png",
    "128": "icons/128.png"
  },
  "background": {
    "scripts": [
      "js/background.js"
    ],
    "persistent": false
  },
  "devtools_page": "devtools.html",
  "browser_action": {
    "default_popup": "popup.html",
    "default_title": "__MSG_extName__",
    "default_icon": {
      "19": "icons/19.png",
      "38": "icons/38.png"
    }
  },
  "options_ui": {
    "page": "options.html",
    "browser_style": true
  }
}

ghost avatar May 12 '20 18:05 ghost

I think you need to add content script in your manifest.json, the file should look like this:

  "manifest_version": 2,
  "name": "__MSG_extName__",
  "homepage_url": "http://localhost:8080/",
  "description": "A Vue Browser Extension",
  "default_locale": "en",
  "permissions": [
    "<all_urls>",
    "*://*/*"
  ],
  "icons": {
    "16": "icons/16.png",
    "48": "icons/48.png",
    "128": "icons/128.png"
  },
  "background": {
    "scripts": [
      "js/background.js"
    ],
    "persistent": false
  },
  "content_scripts": [
    {
      "js": ["js/content-script.js"]
    }
  ],
  "devtools_page": "devtools.html",
  "browser_action": {
    "default_popup": "popup.html",
    "default_title": "__MSG_extName__",
    "default_icon": {
      "19": "icons/19.png",
      "38": "icons/38.png"
    }
  },
  "options_ui": {
    "page": "options.html",
    "browser_style": true
  }
}

Then in the dist directory you should have a js folder with your content script inside.

jatanassian avatar May 12 '20 19:05 jatanassian

config include content-scripts is needed, beside cause build to compress to dist folder need be support, does I change the content-scripts file after that will be reloaded?, currently I config in mainifest.json it same work but hot reload is not, my content-scripts need include jquery how do I do that

trgkyle avatar Sep 21 '20 09:09 trgkyle

Screen Shot 2020-09-21 at 17 30 43 Screen Shot 2020-09-21 at 17 32 30 Screen Shot 2020-09-21 at 17 32 44 Uploading Screen Shot 2020-09-21 at 17.33.05.png…

trgkyle avatar Sep 21 '20 10:09 trgkyle

Screen Shot 2020-09-21 at 17 34 02

trgkyle avatar Sep 21 '20 10:09 trgkyle