I need to close tabs related to the extension, like tabs with url chrome-extension://<extension-id>/index.html, when a browser closes
In the background script, I tried to close tabs with chrome.tabs.remove function when chrome.windows.onRemoved event fired, but looks like it fires too late when tabs not available. Also, because Chrome doesn't open immediately, I tried to use chrome.windows.onCreated event, but turned out it only worked on my computer with Windows and didn't work on Mac.
Am I doing something wrong or maybe there is another way to close them, like adding a script on every page that will be executed when the browser closes?
Related
I am learning how to make chrome extensions and for my extension to work on every tab i have added the following event listeners in background.js:
tabs.onActivated, tabs.onCreated, tabs.onUpdated, and browserAction.onClicked(this one is used to change the flag am sending in message every time the extension button is pressed)
for all these events i send a message to one of the content script js file and that file changes some content according to the recieved message.
Problem is: If i start chrome and the extension isn't active yet, on activating the extension i need to refresh all the opened tabs for it to work otherwise it doesn't send any messages to the content script of the opened tabs, even on clicking the extension icon.
Is there a way by which the extension can start working immediately as i start it without the need of refresh?
I'm following this tutorial on how to use DevTools to insert breakpoints. I've opened the example page and have added a breakpoint on the click event, as in part 2 of the tutorial.
However, when I click the button, DevTools does not highlight function onClick() { in the get-started.js file, as the tutorial says it will. Instead, it highlights a minified function in a minified file (end.min.js):
Why is this happening? And how can I fix it? I would like to follow the tutorial, but it's pretty difficult with the breakpoint being added to the minified file.
I am not sure where end.min.js is even coming from: the Network tab doesn't show it being loaded. I'm not sure if it's related, but when I try to view the source of the page, Chrome shows the "loading" icon forever.
Is Chrome doing something clever with
It seems like an extension (I'd say a password manager) is adding event listeners too, and your breakpoint first catches this listener.
You can either test with the extension disabled (you may need to refresh the page), or just press "Resume" to go to the next listener.
Are you sure you're following the tutorial? I have followed this:
DevTools lets you pause your code in the middle of its execution, and
examine the values of all variables at that moment in time. The tool
for pausing your code is called a breakpoint. Try it now:
Go back to the demo and open DevTools by pressing Command+Option+I (Mac) or Control+Shift+I (Windows, Linux).
Click the Sources tab.
Click Event Listener Breakpoints to expand the section. DevTools
reveals a list of expandable event categories, such as Animation and
Clipboard.
Next to the Mouse event category, click Expand
Check the
click checkbox.
And the expected error shows:
Also you have to activate pause on caught exceptions, and seeing the image that you have provided it seems like you don't have that activated.
But I see if you open DevTools when you reload the page, another error pops up, maybe if you close DevTools, reload the page and try again?
How to get a warning massage if i accidently click the close button of the chrome browser which have multiple tabs opened at that time?
I am a regular user of Crome and having this problem while using it. I normally open multiple tabs inside a single browser but sometimes i accidently click the close button of browser and as soon as the button is clicked crome does't give any warning issue about multiple active tabs and close the entire window.
Is the end user like me is browsing on normal crome window then he can open the websites again by checking the web history but if he is browsing inside private browser then he can't do anything(this happens with me very regularly because i normally browse in private browser). On the other hand if you accidently click the close button in mozilla which have multiple tabs open it throws a warning massage to the user and asks for his wish.
Go find an extension called "Keep One Pinned Tab". It may not be exactly the function you need, but if you search for other extensions, I am sure there is such an extension that does just that. If you can't find one, I suggest to learn how to develop extensions and make one yourself, you can share it with others when it's done.
I have never used it, and after few attempts I feel like i will never get this. I feel this little program has potential but after finding out chrome has multiple child windows i don't think i know what's going on so please help...
I need a script that reloads the page on the current tab of chrome whenever i press Ctrl+R without switching to chrome and then little variation of that key to actually switch and refresh. Like lets say Numpad 1 for just refresh and Numpad 2 for switch and refresh.
Adding on to BGM...
Google Chrome - Hotkeys
https://support.google.com/chrome/answer/157179?hl=en
Activates the Google Chrome window
WinActivate,ahk_class Chrome_WidgetWin_1
Switches to the next tab.
ControlSend,,{Ctrl Down}{Tab}{Ctrl Up},ahk_class Chrome_WidgetWin_1
Switches to the previous tab.
ControlSend,,{Ctrl Down}{Shift Down}{Tab}{Shift Up}{Ctrl Up},ahk_class Chrome_WidgetWin_1
Ctrl+R : Reloads your current page.
ControlSend,,{Ctrl Down}r{Ctrl Up},ahk_class Chrome_WidgetWin_1
F5 : Reloads your current page.
ControlSend,,{F5},ahk_class Chrome_WidgetWin_1
Here is, basically, what you need to do:
Create a hotkey to run a sub.
Set Chrome as the active window (this will "switch") to Chrome.
Send the hotkey for refresh (usually F5)
If you can scramble a sample script together and post it, I'll help you debug it.
Is it possible to access a Chrome Extension from outside the browser?
I would like to be able to run a command from my text editor (MacVim) that refreshes the page on which I am working. From reading the Chrome Extension documentation it looks like I could try something really hack-y, like opening a page that uses Chrome message passing to refresh another page, but there does not seem to be a strait-forward way to do this.
I am running Mac OS X. I've tried the shell command:
$ open <url>
But that opens a new tab every time in Chrome, so this doesn't help when I'm using the developer tools
You are right, there is no straight forward solution.
Your hacky approach is the simplest way to go. Only instead of messaging I would put a tab creation listener into background page, and when a tab with some special URL is created (http://example.com/?do=refresh) - close it and refresh the next selected tab. You will see new tab flickering, but that's as good as it gets.
You can also look into using WebSocket API, for which you would need to write a server side app (which you need to call from your editor somehow). Not sure how this all might turn out.