I'm writing a chrome history extension, and I was wondering if there's a way to detect when the user clicks a link.
Instead of injecting listeners to every single link via Content-Script, can you utilize: chrome.tabs.onUpdated event? There are many events as well.
But since you stated history, you can use the onVisited event, which fires when a URL is visited.
It would be better to utilize the extension framework instead of relying on content scripts all the time which might become messy.
Related
I want to analyze a website that is not mine.
So, I want to use Javascript to do it at my end in the browser.
After I click a button on the website I want to trigger a timer and as soon as a notification from the website comes back, the timer should stop and save the notification that came back.
How can I do this the easiest way?
I cannot give you the link to the website, because it's hosted in a private network.
My first question would be, how I can log all events that are triggered on a website to the console, so I know the name of the button I want to wait for.
Thanks!
dave
All events on a specific DOM node:
To see all the events for a specific DOMnode, or window (only works on chrome i believe, didnt test it elsewhere):
getEventListeners(window)
this will give you an object with all the events, then you can intercept them with
window.addEventListener(eventName, fn, true);
The whole application:
this way your event will be called whenever an event on that node is triggered (window in this case)
if you want absolutely all events on the whole app, you can achieve it with using something like firebug
Specific event on a specific element:
if you want a button click only, you can do the following:
var specificButton = document.querySelector('#specific-button')
specificButton.addEventListener('click', function() {});
Implementation:
if you do not own the sourcecode, you can use something like greasemonkey or tampermonkey to inject your javascript into the page.
if you are using it on a server, you can use cheerio to parse the returned html from the get request, and apply queries on it, but you will lose the ability for listening to live events from io devices.
If I understand you, the easiest option I see is to open your browser developer tools and using the console get the button (document.getElementById, i.e.) and change its onclick callback, including a call to the old callback in your new callback, and trigger your timer.
To intercept the response to this button (I assume that it triggers a network request), you'll have to analyze a bit the code of the web to see how you can detect it.
You could also edit the website javascript throught "Sources" tab of your browser's dev tools.
It's an idea. I have never done something like that. I have to admit that it sounds a little weird to me.
I am very confuse and not sure either javascript or jquery can trigger keyboard event like Shift+Q or Alt+Q from button click. I already looking on this forum and also download some of js file like key-event.js and crossBrowser_initKeyboardEvent.js but I still cannot get a result what I want.
My situation is I need to trigger ALT+q key from button html. This should be automatically proceed and will be effect not only inside html(browser) but also on desktop client.
Thanks you.
The effects of keyboard and mouse events fired by Javascript within a web pages are limited to the contents of those web pages. These events cannot reach outside of the web page to trigger keyboard shortcuts in the browser or desktop.
I read these two questions:
How can I detect browser tab refresh or close using javascript
and
How do I detect a page refresh using jquery?
which suggest binding to 'onbeforeunload' and also binding on F5 and Ctrl-R key presses, which is good advice.
However, most browsers have a refresh button on their address bars, like this in Chrome:
Question is: is it possible to detect and bind to refresh event of browser's address bar's refresh button?
By binding onbeforeunload to windowlike this window.onbeforeunload it should trigger in most browsers. check this fiddle. It seems it's not supported on IOS devices.
For IOS apple docs suggest using pagehide see apple page on Handling Events.
The load and unload events may not work as expected for back and forward optimization. Use the pageshow and pagehide events instead.
Keep in mind that this will also trigger on all other kinds of navigation away from the page. Such as close, tab close, back/ forward navigation, link navigation and address bar navigation
Checking if the browser is reloading versus navigating away from the page I'm pretty confident is not possible, due to security/ privacy reasons not being able to give you the destination url. You could eliminate link presses by using it is an condition when firing the onbeforeunload.
Edit: If you need to check if the page has been reloaded however, you could use sessionvariables or cookies to store that the user has already opened the page once before.
I am developing a custom translation extension for GMail in chrome and need to trigger the content script when the user clicks on an email in his inbox.
Since GMail uses AJAX, I decided to use the DOMSubTreeModified event. My extension works, but it seems via console logging that the function that sits the translate keeps getting executed constantly, even though the email text remains the same.
DOMContentLoaded does not trigger. Can anyone suggest any alternative I can use? I guess a timer or something in GMail constantly updates the page and makes minor adjustments. I had even narrowed the element on which the event is generated.
It appears that you should be using gmail-specific events to know when a new email is loaded, not generic DOM events. This add-on is not official Google code, but if you look at how it works, you could probably discover how to observe all sorts of gmail events or you could just use it to solve your problems.
I've made a single-page web presentation that changes it's content based on user events like clics, previous viewed content, source refers...
During usability tests I've detected that some users tend to use the back button and that leads them to the previous page, which is not what they want. They want to go back to the previous content.
As we are in the final stages of the production the easiest for me would be to create an event that fires with clics in the back button. The second easiest way would be to detect changes in the window.location.hash and fire an event.
I don't know how to do either.
It is necessary that this feature works in IE8+ FF4 and it's not that important on older browsers, as long as it doesn't compromise other features already implemented.
The page uses jQuery.
Use this http://benalman.com/projects/jquery-hashchange-plugin/ or http://benalman.com/projects/jquery-bbq-plugin/ this.