I'm using chrome version 109.0.5414.75 and developping an extension.
And when I call print() method to save a page as pdf file, I can't catch afterprint event.
But when I type Ctrl+P commnad then the event fired and after this, print() method fire afterprint event normaly.
The code is in content.js of developping extension.
The code is very simple in content.js
window.addEventListener('afterprint', (event) => {console.log('After printing'); });
When I save as pdf by print() from console of developer tool, the event not fired. but by Ctrl+P if fired.
This situation happens an environment but on other systems no problem(fire the event).
Does someone have some ideas to solve this?
I can use eventdispatch to deal with it, but I want the timing that saved pdf(afterpring).
Related
I'm attempting to run a function (that sends some fetch calls to an API) inside of a "beforeunload" event handler and the results are mixed. With Chrome it successfully runs my function if the user reloads the page or clicks a link for a different webpage, but it doesn't work if they close the tab. In Firefox the function only runs if they close the tab, but not in any other scenario. When I debug the beforeunload handler in the browser I can see the event handler clearly is triggered but the function inside doesn't always run. I suspect the function I'm trying to feed being async is part of the issue but I don't know why the results would be so inconsistent?
This is how I'm currently writing the event handler
window.addEventListener('beforeunload', async function(evt){
await exitChat();
});
I've also tried not using async/await. Let me know if seeing the exitChat() function code would help or anything else.
Edit: After a bit more debugging I can confirm that the issue, with Chrome at least, is that when the window is closed it can't make it through the entire exitChat() function in time before the page closes. So is there a way to force a delay in the unloading process?
In my Wordpress site, I've created a Modal shortcode, which opens a modal when the modal's "name" is in the hash part of the location.
For instance /#contact-us will open my "contact us" modal.
To do this I have a hashchange event listener on the window, using jQuery, as so:
$(document).ready(function () {
$(window).on('hashchange', function () {
openModal();
});
});
On my laptop, this works pretty fine.
The problem is that when I try it on my mobile phone (Nexus 5 - Chrome & Firefox), and even when I use Chrome's devtools emulator, when clicking on an anchor with a href="#contact-us", it won't work - The hash in the url changes but the event handler is not being called.
The weird thing is if I manually add a hash to the url, the event handler will be called.
I thought there might be another handler that is stopping the propagation or something like that, so I tried using jQuery's _data function (as mentioned here) to see if there are any handlers, but couldn't find any.
So I guess my question is, why isn't this working? and what else can I do to find out where the event is "getting lost"?
I am trying to wire some analytics into the onStartup event of my Chrome Extension per the docs. However, the event never seems to fire when the extension is opened via the icon in the browser.
Note that the onInstalled event in the below code fires as expected when the extension is installed, reloaded, etc.
chrome.runtime.onInstalled.addListener(function(details) {
console.log('Extension installed: ' + details.reason);
});
chrome.runtime.onStartup.addListener(function() {
console.log('Extension started');
});
Note I'm running Chrome v37 - the onStartup event has been available since v23.
You are trying to invoke code when a popup is opened. This is not the same as "starting" the extension - the chrome.runtime.onStartup event normally fires once per browser launch.
chrome.browserAction.onClicked event will not fire when a popup page is set; instead, you need to execute some code in the popup page itself (and that code will be executed each time the popup is opened).
You can simply send your analytics event from the popup page itself. Or, if you prefer sending it from the background page, you just need to message it.
I am writing an chrome extension related with Github. I want to trigger a function when user click to public activity tab on Github user profile page.I am adding pjax success event listener in extension but not triggering anytime.
I am adding jquery.pjax.js to manifest.json and adding below code in contentscript.js but function not calling when pjax request succeed:
$(document).on('pjax:success', function() {
console.log("Hello");
});
How can I run function when pjax succeed in chrome extension?
I want to execute Firebug lite in my webengine and then call some methods from the script. First i execute the script as described in here and its work fine. The problem starts when I try to call and execute a method inside from the script. First I have a 'Exit' button in the webview and in the event of the button i call the method shutdown to close the script. Below is the code:
eng.executeScript("window.Firebug.shutdown();");
The firebug immediately disappears from the webview. Then I have another button 'Start' and in the event i want to open again firebug with the code below, but nothing happens. No errors or exceptions appear and seems that the script executes correctly.
eng.executeScript("window.Firebug.startOpened=true;");
I also try the method initialize() eng.executeScript("window.Firebug.initialize();");and then i get an exception like below:
netscape.javascript.JSException: TypeError: 'undefined' is not an object
at com.sun.webpane.platform.WebPage.twkExecuteScript(Native Method)
at com.sun.webpane.platform.WebPage.executeScript(WebPage.java:1438)
at javafx.scene.web.WebEngine.executeScript(WebEngine.java:811)
at student.WebBrowser$2.handle(WebBrowser.java:126)
I also want to know which method in the script executes when the user clicks the ShowInNewWindow button and from an JSObject in javafx catch the event and open firebug in a new form.
Thanks in advance.