Creating a browser action button to open chrome developer tools - google-chrome-extension

I have a chrome extension I am working on, which lives in a devtools panel (http://developer.chrome.com/extensions/devtools.panels.html).
I want to add a button to quickly open up my extension. I added a browser_action button just fine, but I can't find any information on launching developer tools from a browser action.
Is there a way to open developers tools and switch to my pane from a browser action button?

It seems unlikely that this is possible or will ever become possible. From Chromium Issue 112277:
We only allow explicit devtools opening.
While the issue described there is slightly different from your use case, your needs still seem to run contrary to the requirement of "explicit dev tools opening".
I read "explicit devtools opening" to mean "only open devtools when the user explicitly requests devtools". This reading is incompatible with allowing extension buttons to open developer tools. You could have a button that appeared to do something (say, redirect you to a website) but when clicked, actually opened developer tools -- you've just opened dev tools without the user explicitly asking for it, which is inconsistent with my reading of "explicit devtools opening".
Consider the theoretical statement, "We only allow explicit deletion of user data." Certainly that directive would preclude allowing an arbitrary extension button from deleting user data, wouldn't it? Even if the user explicitly clicked on a button, they didn't explicitly opt to perform a delete.
Perhaps you could read "explicit devtools opening" more loosely to mean "open devtools only in direct response to user action" which would leave open the possibility of future support for this functionality.

Related

Are there any chrome extensions that are free to inspect and understand?

So I have recently started working on building a Google chrome extension, and found the entire landscape fascinating to say the least. While I was checking to understand how some of these extensions work, I found that many of them have blocked 'inspect element'. I found only 'Adblock Plus' which allows it.
My question:
Are there any more complex interesting chrome extensions that allow inspection?
Any way to find such extensions or how to get around the ones that have blocked viewing?
As a beginner, I would appreciate any advice or tips in this area.
You can inspect and debug all extensions right in the browser.
You may need to use a different method of invoking devtools.
To inspect the popup you can enable developer mode switch in chrome://extensions and then right-click the extension's icon in the toolbar or click ... inside the puzzle piece menu that lists all extensions, then choose Inspect popup.
Similarly, to inspect something shown in the tab, you can open devtools via the standard hotkeys like (F12 or Ctrl-Shift-i in PC) when the cursor is focused on the toolbar even if the page actively intercepts these hotkeys and/or the context menu.
You can also open devtools from the browser menu "More tools".
There's also chrome://inspect.

Instead of running the action, chrome extension menu appears when clicking a page action

I have a Chrome Extension (page action). The extension is loaded in developer mode (not from the store).
The extension is used in two sites, both of which URLs are in the manifest.
When I go to one of the sites, the page icon is enabled and when I click it, it runs fine.
When I go to the other site, the extension icon is also enabled but when I click on the extension, instead of running the action, the extension menu appears (as if I had right-clicked the icon instead of clicked it).
When I hover the page action icon, in both sites I get the text "Has access to this site".
Which are possible causes for this behavior?
Something definitely changed with the manifest.json handling of the most recent Chrome update. (In my case, "Version 72.0.3626.96 (Official Build) (64-bit)" on Windows.) My extension stopped working in a way similar to what you describe.
The solution to my problem was to remove the specific url permissions I had specified in the "permissions" section, and replace them with <all_urls>. I tried tightening them back up again, but the only other thing that worked for me was https://*/*.
I tested this on several machines that had the previous version of Chrome and they had the same behavior... successful operation before the Chrome update, no response after. The icon displayed properly and showed "Has access to this site", but my background page refused to run.
Good luck! Hopefully this helps!

Can my chrome extension open a link in a different profile?

I use two different Chrome profiles (users) on my laptop: one for my work stuff and one for my personal browsing.
Sometimes I click a link from HipChat and it opens it in the personal profile even though it's for work (e.g. login.work.com). (This is because I happen to have been in my personal chrome window most recently.)
I'd like to make a chrome extension I can install in my personal profile to match the URLs of *.work.com and send these over to the work profile window.
I haven't found a way to open a url into a different profile. Anyone know of a way?
(A hacky idea I got from reading https://superuser.com/a/289618 is maybe I could shell out to something along the lines of google-chrome --user-data-dir=$work_profile, but I'd be happier if there was a JS API and I didn't have to ask permission to run programs on the user's computer.)
Dropping an answer in case it's still useful to anyone.
I built my chrome extension CopyTabs (https://chrome.google.com/webstore/detail/copytabs/obkbjogekcjalnaebheboejhfkamadkg) to do something similar. It is able to open links, current tabs, selected tabs or windows, in the current chrome user profile, another chrome user profile or another browser entirely.
I made use of chrome.exe --profile-directory="profileName" to open URLs in a selected profile, but this has a handler that runs on the user's machine, with profileName being the internal name of the chrome profile, for example --profile-directory="Profile1" instead of --profile-directory="My Name As Profile".
So to answer your question, no I don't think there's anyway around a local handler on the user's machine to achieve this functionality.
Though the question is an old one but maybe someone is looking for an answer.
In the new versions of chrome when you right click on a link, in the pop-up menu, there is an option to open the link in another profile. For this to work, ofcourse, there need to be multiple user profiles in Chrome.
Works like a charm!
Hope it helps.
There is no solution for this. It would need a handler, a separate program, that captures the URL before it reaches Chrome, parses your preferences for which URLs go to which profile and then starts the specified Chrome installation with specified profile flags.
However, afaik, such a program does not exist (at least on Windows).
Further, Chrome cannot even select which profile out of many is selected, when Chrome is started from the OS "call URL to be opened" function and NOT started by user-activated clicking on a Chrome application shortcut (with specific profile selection instructions).
Naturally, the latter works 100% wonderfully on Firefox, which has built-in profile selector after the browser has been started, and regardless of which method was used to start Firefox (user click on Firefox icon or OS pipe of "open URL" to Firefox).
So; no solution in Chrome.
I believe that Account Surfer should be able to do the things that you're looking for. Here's an overview from Windows store:
Quickly switch between accounts and browsers with Account Surfer.
Decide what account or browser to use when opening the link.
Read more:
https://dospolov.com/posts/handle-chrome-profiles-with-account-surfer
https://trello.com/b/QOLCmlg3/account-surfer-roadmap
Yes u can:
install extension like this https://chrome.google.com/webstore/detail/open-in-ms-edge/mjoebkkejejidnkfdekpbooceogbapnf
copy address of profile (for example: C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe" --profile-directory="Profile 2)
Insert it in settings of extension
profit
OR
Use Browser Chooser 2
The app finicky did the trick for me. You can check out this link for installation and configuration for the same.
Finicky example configuration

Chrome extension pauses before loading

Question
How do I reduce the time between clicking an extension icon and the content being displayed?
Support
I'm making a very simple extension. It loads quickly once it's started, but there is a bit of a delay between clicking and the popup loading. I've added a gif of this here. (The gif gets a bit hectic to look at, so I've put it under a link so that it doesn't burn your eyes!) It doesn't really do it justice as it loads faster on my machine than other people's for some reason.
This question (Slight loading delay with chrome extension popup) seems to address the same question, but it doesn't have an answer. I think that this question (load chrome extension popup faster) addresses this issue too, but its answer seems to be addressing a different problem.
My repo is here: https://github.com/bvn-architecture/shackleton
If I profile the load time of the extension it starts measuring from when the popup appears:
This implies that there is something on the screen about 5ms after loading. It doesn't include the pause.
I think the delay you are facing is due to the time necessary to launch a new task process in Chrome.
Open Chrome menu > More tools > Tasks manager, you will not see any reference to your extension.
Now click on your extension browser-action icon, you will see that, after some various delay, a new entry called "Extension : BVN toolbar" will appear in the tasks manager. Once the task appears, your popup opens.
Some tests
If you test the My Bookmarks sample extension from the Chrome extension samples, you will see the exact same behavior.
Now if you have a look at some other extensions like Adblock Plus for example, which uses a browser-action icon/popup like you, you will see that its popup opens much faster than yours.
If you check the tasks manager again you will see a task named "Extension : Adblock Plus" even when the popup is not opened.
Explanations
This is because many extensions (like the Adblock one) are using persistent background pages which are single long-running scripts existing for the lifetime of your extension (until you disable it, close your browser etc.)
As mentioned in the documentation, the use of persistent background pages is discouraged in favor of event pages (non persistent ones). But in your case, using an event page will not solve your problem because when the event page is not actively doing something, it is unloaded to release resources.
Solutions
The easy way
Defining a persistent background page in your manifest.json file will solve your problem but will result in a not really necessary memory usage to keep your extension task "alive" (and your extension don't need it to work):
"background": {
"page": "popup.html"
},
The other way
Submit the question / problem to Google. Maybe they can perform some optimizations for such case or they will provide you a better solution. And you can explain that this encourages the use of persistent background page instead of event ones :-)

Chrome Extension: Replace context menu item action

is it possible to replace the action of an existing item in the context menu in Chrome. Simple example, every time I press "Inspect Element", it opens another developer tool extension instead of the default.
It is not: at the moment, devtools APIs only function if the web inspector is open. There's no mechanism to open the web inspector for a user, it has to be her explicit choice.
That said, it sounds reasonable to give an extension the ability to hook into an element's context menu. That might be a good idea for an extension to the existing devtools or Context Menu APIs. Would you mind filing a request at http://new.crbug.com/? I'll make sure it lands in the correct queue.

Resources