Chrome Extension: How to run Javascript on page load (without popup open) - javascript

I have a Chrome extension that does word substitutions on pages. Currently I have a popup that opens when I click on a browser action which lets the user control whether or not to perform the substitutions. I also have a background script running that sends a message to content scripts when a page refresh happens using a chrome.tabs.onUpdated event handler.
My problem is that when I refresh the page no substitutions are made unless the popup is open (which is only possible when I have the inspect elements panel open on the popup, because otherwise the popup closes when I refresh).
Has anybody had experience with this behavior before? What additional instrumentation should I add to diagnose the problem? Is there a different extension architecture/code arrangement I should be using?
Thanks in advance!

If you use localStorage on a given page you can probably store whether or not to substitute words. I think refreshing a page is similar to opening a new tab, so your script gets reinjected/reloaded rather than staying open and receiving an onupdate message.

Related

chrome extension setPopup is not propagated immediately

I'm working on chrome extension and I want to have 2 pages one main popup and then on click on specific button I want to replace it with other one(some settings page) so far I managed to change it using
chrome.action.setPopup({ popup: "settings.html" })
but problem is in fact that it's not immediately propagated, I have to click on extension to close it and click again to open it to be able to see settings page, did I missed something or what is the preferred way in such case?

Is it possible to inject a chrome extension popup into current webpage without using react?

I'm currently working on chrome extension and I'm dealing with a content injection problem.
In my extension when user clicks the button inside the popup, he has possibility to choose DIV from the webpage he's currently on and then he can return back to popup to choose options for that chosen DIV.
The problem is that I can't force the popup to be open when user clicks outside it (actually I can with open popup console, but it's not a solution here) and the popup.html is reloading every time extension is shown to user.
So I came up with an idea that I can inject a popup into an iframe in the webpage to have control over it's behaviour but I found similar solutions only connected with chrome extensions based on react. Is it possible without any framework?
Any help would be greatly appreciated.

How to execute an action when user clicks browser action and there is a popup (Chrome extension)

I'm trying to create a Chrome extension that features a browser action and a popup. I need to refresh the content I serve in the popup every time the user opens it, but since the on clicked event will not fire if a popup is assigned to the browser action, I don't know how to trigger the logic to refresh the content.
I'm trying to do this in the background page, but I understand that that might not be the best way. Does anybody have an idea of how to approach this?
Thanks for any help.
The popup is created from scratch every time the user opens it, so any javascript file you include using a <script> tag will be executed. You can include any logic you need there.

JavaScript simulate physical click on a link to bypass pop blocker(Not Jquery)

I am opening a popup after main window load.
Problem:
When user actually click on link the popup opens without complaining anything.
But when I am using Javascript call to click on href, I am getting popup blocker.
I am suspecting that, browser identifies that, popup is opening without any actual operation by user and that's why it is blocking popup.
In herf, I am calling a javascript method to open the popup.
I searched all the questions regarding opening popup and simulating the click like this, these works fine to simulate the click but still getting popup blocker.
Is there any workaround to fool browser?
You can't fool the browser per-se in this scenario. You could however, launch a div as an overlay on the main window if that's an option.

how to open web application in a browser without navigation buttons

I have a web application, and I want to disable the Back button.
I read and found that I can open the browser without the navigation controls with the function window.open(...).
This is the code:
window.open (mywebappURL,"mywindow","status=1,toolbar=0");
I tried to put it in my Main.Master page, but I get an infinite loop and the new window is opened as a popup window of my application.
Does anyone knows where should I put this code to get my web application opened in a browser without navigation buttons?
Thanks,
Inbal.
try this on the link's onclick() event
function openPopup(){
var pathname = (window.location.pathname);
window.open(pathname+'somePopup.html','','width=800,height=450,resizable=yes,dependent,screenx=80,screeny=80,left=80,top=20,scrollbars=no');
return false;
}
and in the html
click me
To answer your question directly, make sure the window you're opening is a different URL than the window that's initially visited. So your visitor might arrive at www.example.com/index.html which then opens www.example.com/popup.html
If you open index.html again, the new copy will immediately open a popup, which will immediately open a popup, and there's your infinite loop.
However, as several people have commented already, this is generally discouraged. Among other disadvantages to this approach, popup blockers will likely interpret this as trying to launch a popup advertisement, forcing your visitors to recognize what's happened and change their settings.

Categories

Resources