Reputation: 101
I'm trying to write a Chrome plugin that listens to all mouse/touch events.
I have sites like google maps that won't react. If a website modifies the mouselistener
by prevent default?
Is there a solution that works for all sites?
I something like this possible?
//Sending user interaction to bg site
$(this).mousedown(function(e){
chrome.runtime.sendMessage({userInteraction:true});
console.log('keyboard user interaction sent');
});
chrome.runtime.onMessage.addListener(function(details) {
console.log('message to background javascript: ' + details);
});
Upvotes: 0
Views: 1601
Reputation: 2231
I have also work on a related subject.
There is some problems with global events handling with extension.
In this case, your handler will be executed after the handler of the loaded page. By some way, your handler can be simply ignore, for exemple if the loaded page handler redirect the user to an other page.
You can avoid this problem by injecting a <script>
tag with your handler. This way your handler will be executed on the loaded page Javascript VM and will be able to replace the page handler. It's uggly but it work. The bad thing with this strategy is that it will probably break the existing javascript of the loaded page.
This is a google limitation for security reasons. You can't execute an extension on an official google page like the Google Store for example.
There is no way, in my knowledge, to bypass this security restriction.
In conclusion, I would say that there is universal way that will work for every site. And I want to say that this is, I think, a good thing. Google Chrome Extension are already enough security breaker...
Upvotes: 1