I'm calling window.scrollBy(0, window.innerHeight) in a Chrome content script, from a mouse registered wheel handler. This is meant to scroll the page by its page height (same effect as PageDown key), but I notice that Chrome immediately undoes the scroll. The net effect is only a page flicker, due to the programmed scroll and and its immediate undo.
Not surprisingly, if I execute that function from the page console window, it works as expected.
Weirdly, if I call that from a setTimeout, the scroll works as expected. The magic timeout I discovered by binary search as 175ms--anything less than that, the scroll is undone. I tried using Promise, too, but it's the same. I wonder why this is.
FWIW, this works without any setTimeout hoops on Firefox.
Turns out this was due to the handler having been registered as passive. Registering the handler with {passive: false} got the scroll working as intended. More info here.
Related
In FireFox extensions, the Panel/Popup that opens on the Toolbar sizes itself outside the browser window, if needed, so that we see every populated elements in the panel. In Chrome however, the popup/panel is only drawn until the browser window's boundaries. So, if the user resizes the browser window small enough, you don't see the entire popup.
I checked the documentation and couldn't find anything. Is there anything that can be done to show the entire popup?
This seems to be OS-dependent (can be reproduced on Linux and Win7, but not Win10).
As an extension author, there is nothing you can do to control it, this is just how the browser renders its content. You could submit a bug report.
if you click on the browser button, appears a page as a popup page.
with my program you can turn on music, from the body of the page.
when the window appears, music can be turned on, but when the window goes away, music is stopped.
does anyone have an idea how it stays turned, without popup appeared to stay?
Indeed when the popup goes away everything gets torn down.
Depending on how you play the music it might not be available in the background page either. Good luck.
Given a webpage with a Javascript animation running on a timeout, does the browser check whether the element being animated is hidden or is it cheaper for the browser to fire a repaint?
Very late answer but thought I'd throw it out there - Yes the browser knows internally if what needs to be repainted is in the viewport and prioritises the repaint accordingly (so changes the user will see happen faster). Firefox has the mozAfterPaint func which fires after repaint, and the mozPaintCount property which continually increments with every repaint and can be checked accordingly.
I am looking for a cross-browser solution for establishing when there has been a repaint but it is much harder in other browsers.
I'm writing a chrome extension.
When i click the browser action button in the first time - all goes well.
When i click the browser action button the second time, after several minutes of not clicking it, it takes more than 10 seconds until the popup is shown.
I've tried commenting out all of the periodic methods in the background and all of the methods in the load event of the popup, but it still doesn't shown immediately.
any suggestions?
I had a similar issue with the popup when I was adding an iframe to the popup. Chrome would wait with showing the popup until that iframe was loaded.
For me the fix was wrapping the code that added the iframe to the HTML in:
setTimeout(function(){
// Code here
},0);
This way Chrome showed the popup first, after which it begin with loading the iframe.
Maybe you have a similar problem?
i have seen this behavior before when you have a long running ajax call that you are doing on popup load.. hard to tell further without code samples or description of what you are doing
Thought about it some times, and I decided to ask:
Why do a browser don't block the screen when doing a postback?
I have always been bothered by the fact that web browsers usually (can't say I've used them all) doesn't block the screen after I click a button that produces a postback. As I see it, during post a browser is expecting the server to send some information back. If it doesn't, the connection will time out and the page will be replaced by an error. If the server answer, it has to be with a web page; In other words, there's no possibility to keep the current web page rendered.
But it happens rather often that I click a button, realize that I forget to check a checkbox and so I click it, but to no avail. I know, I should have realized that clicking the checkbox wouldn't help, but hey, I usually doing stuff in auto-mode.
I think that it could be that the browser blocked the web page after you pushed a button or clicked a link that will produce a post back, so you couldn't press anything. But for some reason most browsers don't. Why?
The browser only shows what the page says and does what the script tells it to. If the page designer didn't implement anything to disable input during the connection, the brower leaves it up. In some cases this can be useful, such as when the input devices need to be available (although I can't think of a good example off the top of my head). A quick way to disable them (aside from disabling each individual input) is to have a hidden div with a z-index higher than the rest of the page become unhidden with a low opacity (screen looks slightly tinted, div prevents anything underneath it from being used) and then hiding it again when a response is received.
Ultimately it's just the result of a design choice. Does that answer your question?
When a browser blocks input is generally intentionally programmed that way.
Postback and clicking a button is not coupled because a button is not always used to do a postback.
Even when the browser is doing a request to some server in background, this request is not always fired by a button pressed (see Ajax)
In other words, there are much more complex scenarios than "push button, then postback", in order to cover every scenario, browser let this control to the programmer.