Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable Vue devtools in production mode for chrome extensions?

I'm building a chrome extension, and using a vue-cli webpack config. I'd like to be able to use the vue devtools after running the npm run build command.

I tried to add Vue.config.devtools = true; in main.js, or change NODE_ENV: '"production"' to NODE_ENV: '"development"', but vue devtools is still not showing up.

What can I do to enable vue devtools in production mode?

like image 566
Alex Efremov Avatar asked Jun 27 '17 09:06

Alex Efremov


People also ask

How do I add Vue Devtools to chrome?

Install on Chrome Go to this page on the Google Chrome Store: https://chrome.google.com/webstore/detail/vuedevtools/nhdogjmejiglipccpnnnanhbledajbpd and click Add to Chrome. The Vue. js devtools icon shows up in the toolbar. If the page does not have a Vue.

Why is Vue Devtools not showing?

The Vue devtools don't show up Check if you have the extension installed. If you are on a live website, there is a good chance it's using a production build of Vue. Set the __VUE_PROD_DEVTOOLS__ environment variable for Vue 3 when using a bundler like Webpack (more info).

How do I turn off Vue Devtools in production?

change console. log globally to filter out this particular message → not "The Vue Way" modify the source code of Vue → not "The NPM Way" kindly ask the Vue developers to remove this → takes time + change likely to be refused for business reasons.


2 Answers

First,use Vue devtools in Chrome ext Development environment is enabled.

Experience

These days I'm developing a Chrome browser plugin.I found that __VUE_DEVTOOLS_GLOBAL_HOOK__ undefined.

Although not a big problem, but I want to solve it.I have searched a lot of information online.

example:

1.open chrome-extension://<hash>/app.html

2.set Vue.config.devtools to be true

3.grant Vue Devtools ext file access

but all doesn't work.

Solution

As we know, vue-devtools is an essential piece of the Vue ecosystem, but it is currently tied to a web browser.

But now There is a package provides a standalone vue-devtools application, that can be used to debug any Vue app regardless of the environment. Now you can debug your app opened in mobile browser, safari, native script etc. not just desktop chrome or firefox.

This package name is vue-remote-devtools, which is a standalone electron shell to remotely debug Vue apps!

Let's have a try:

Following the README.md steps,

  1. Install the package globally:

    npm install -g @vue/devtools

  2. run in your terminal: vue-devtools

    you will see a electron app appear like this Electron Shell

3.inject the script tag to your Chrome Extension .html file.

Warning

Due to Chrome's Content Security Policy (CSP) restrictions on plug-ins,Chrome Extension's web request may be blocked.

At this point you need to modify the Chrome Ext configuration file manifest.js.

content_security_policy: "script-src 'self' 'unsafe-eval' http://localhost:8098; object-src 'self'"

Although you can copy content_security_policy to the corresponding file manifest.js, but I still hope you can find out what the CSP is:

What is Content Security Policy (CSP)

Finally

Connect Success! enter image description here

Ref:

vue-remote-devtools

DevTools for Chrome Extension Development.

like image 94
John Trump Avatar answered Oct 03 '22 21:10

John Trump


It looks like I have the problem because I'm trying to use vue devtools in Chrome extension. Unfortunately, it's impossible to use vue devtools because extension pages are served over chrome-extension://

Further reading: https://github.com/vuejs/vue-devtools/issues/120

like image 25
Alex Efremov Avatar answered Oct 03 '22 22:10

Alex Efremov