I want to write an Google Chrome extension to prevent a specific webpage to react on blur events.
I know how to do it for the javascript part : I inject some javascript in the page at runtime:"document_start" in order to overload the addEventListener method with my own function.
The problem is with flash parts on the page. Theses can use addEventListener(flash.events.Event.DEACTIVATE,deactivate_method_in_as3);
Of course I'd like to prevent the method call
So I have several questions :
Is it possible to set a security parameter somewhere to disallow Chrome to transmit focus related events to the application ?
Is it possible to modify 'on the fly' the swf file to remove or overide this handler (of course I have no control on that swf).
I also started to use the chrome.debugger.* and chrome.windows.* APIs because they can intercept events early. In that case I have a annoying message saying "tab is debugged by ..."
The swf has a similar handler for flash.events.Event.ACTIVATE so I can try to use it. But how to trigger it when the page is not focused ? (I tried to call focus() on it but it doesnt seems to work.
Any other idea welcome :)
Thanks for reading
Related
I am trying to scrap odd data by Pyppeteer from bet365 follow their UI flow and need for help.
The pages are just like this.
https://www.bet365.com/#/AC/B1/C1/D8/E123540970/F3/
If the match is outdated, just get into one of the matches that not in-played from following.
https://www.bet365.com/#/AS/B1/
For the collapsed button named "Handicap Result" at the bottom of the page, I can normally use my mouse cursor to click on it and make it expand and retrieve its data.
But when I tried to use Pyppeteer's click or javascript to do it, that is querySelector() and click(), it just weirdly failed.
Observing html and xhr after click(), it definitely triggered something and tried to do something, but the content just failed to shown.
I tried to click on different coordinates, key Enter and Space, click with delay, and all failed.
Could someone tell me how could I expand it use javascript?
Was I dissipating wrong events?
Thanks.
This is probably one way they use to avoid scraping.
U tested with pure JS direct from DevTools?
Bet365 its really, really hard to scrape. They use Cloudflare blocking and protection system (including AI to detect autonomous agent like Puppeteer, even if you use stealth mode).
I have a WinForms app that uses a .NET webbrowser control. What I need to do, is wire up an event on the WinForms side to fire when a value is set (via javascript) in the loaded HTML page. I had success doing this with an onclick event of a button, but I can't seem to get it to work with a custom event. I don't know if this is a limitation in what the browser control can attach to event wise.
So essentially, I need that when a JS function is called in the HTML page and sets a value of a hidden input element (or it could be a regular input that I style to be hidden), I need to know that in WinForms. If it helps, I am using browser flags in this application to emulate IE11 instead of the default IE9 engine. The HTML page loaded is also mine so I can modify it any way needed to make this work properly. I would just use the onclick events of the buttons, but this is a gmaps integration where there can be upwards of 2000 buttons generated (one per marker placed) so it seems like a huge waste of resources to wire up 2000 onclick events when any of those button clicks only modify 4 input fields with the data I care about.
This project happens to be in VB.NET, but C# solutions would be fine as well. They can be transcoded or if the solution uses C# specific features, we can move this to a separate DLL and reference it.
After spending a lot of time on this today, I found a solution. It isn't a direct solution to the problem I posted, but it got me to where I needed to be. I am still interested in an answer to the original problem if anyone has one, but for now, what I found I could do was to create a class in .NET that I could assign to the ScriptingObject of the browser control and then call window.external.myFunctionName, where myFunctionName is a function within the .NET class. This works great for my specific problem, but would not work if I didn't also control the HTML page I was consuming with the browser. That is why I am still interested in alternate solutions if anyone has one. Thanks.
This may seem like a simple question, but it doesn't seem to be answered anywhere that i can find.
I am writing an onClick event handler that simply calls dataLayer.push() when an anchor is clicked.
Is dataLayer.push() a synchronous operation?
Will the GET request to google definitely be sent, even though the browser has unloaded the page it was requested from due to the link being followed?
Some browsers show the connection get cancelled, some show it success.
My question is if the computer is slow, is it possible for the page to get unloaded before the request is sent?
This is why i assume that google started using the eventCallback property to redirect the user after the link has been followed.
e.g.
https://developers.google.com/tag-manager/enhanced-ecommerce#product-clicks
This source code does not include the click handler, but implies that the onClick event should stop propogation and let the eventCallback function set document.location.
However, as soon as you cancel the event, all its information has gone.
This (in my opinion) is just the wrong way to do it.
e.g.
(CTRL or COMMAND) + Click opens a new tab on browsers. This will not work unless the onClick event handler allows the prorogation to continue.
Relying on eventCallback also means that if the google scrips didn't load for one of the many reasons it could (but is still unlikely), your links don't work. And your site is broken.
So this leaves the correct way to do it for the onClick event handler to allow the event to propagate and return true.
Which also means that dataLayer.push() would need return after the GET request was sent for any of this to work properly.
Code example:
NOTE: You will get mixed results in mixed environments.
Link
$(document).on('click', 'a', function(event) {
// Is dataLayer.push() guaranteed to fire a GET ?
// data set externally
dataLayer.push(data);
return true;
});
Is there anyone out there that can guarantee that the GET request will get fired to the google server?
Have the google developers forgotten something here?
EDIT: Updated title to be more relevant to the question.
datalayer.push does not send anything to Google. It pushes objects with key/value pairs to the datalayer array. This might contain an event which in turn fires a tag. Whether the tag is sent depends on the setup of the tag, not on the dataLayer.push.
As a consequence, when you write your own click handlers your are yourself responsible to make sure your tags are actually fired.
If you use the built-in click handler you can configure a delay to make sure your tag has time to fire before the link redirects:
Since link clicks usually cause the browser to load a new page and
interrupt any pending HTTP request, you have the option to add a small
delay to allow tags fired by Tag Manager to execute properly before
redirecting to the next page. Checking the “Wait For Tags” option will
delay opening of links until all tags have fired or the specified
timeout has elapsed, whichever comes first.
You should be able to mix both methods (push data on the click, but still use the "native" link click handler for the event).
You can also try to specify "beacon" as the transport method in your Google Analytics tags, on browsers that support this (which I think is only Chrome at the moment) GA will then use the navigator.sendBeacon interface, which sends the data even in case the page unloads.
You might think that Google's solution is not very elegant (but the simple delay has the advantage that it works for all tags, not just for GA), but they have not "forgotten" the problem.
Also solutions that combine GA hit callbacks with timeouts that redirects if the callback fails as proposed i.e. by Simo Ahava somewhere should be be doable with GTM, even if they are probably more cumbersome to implement in GA.
I am working on a HTML5 application framework, run by a SAP JEE application server, build for companies and their intranet and extranet sites. It is based on the grid framework "Semantic UI" and besides that contains a lot of (also third party) Javascript.
I am currently examining a bug, where clicking a specific icon in a menu, when the page is scrolled down, makes the page somehow scroll back again upwards.
Since there is this great amount of Javascript around, I am currently struggling to find the JS code snippet, which is causing this odd behaviour.
I've read this post here, and got to know event logging in Firebug and inspecting event handlers in Chrome, but that didn't really help me.
I found out that using:
$(<my Elem>).on('click', function(event){
event.preventDefault();
})
I can prevent the scrolling, but I still didn't discover the cause of it.
Has anybody some more advice on how to find the real cause of this?
This behaviour might be caused by several different reasons. One of them that is often overlooked is links like Some JavaScript Handler.
When the JavaScript handler does not properly handle the event (e.g. by calling event.preventDefault(), the HTML link will be followed in addition to the JavaScript handler. Most browsers handle a link to an empty anchor tag # by going to the top of the page. This can easily be avoided when using an empty href attribute like <a href>Some JavaScript Handler</a>.
I'm trying to retrieve an image stored in the clipboard using jQuery. So far, I've managed to find a solution which works perfectly using the onpaste event. But, as per the requirements I want the same functionality in a "button click" instead of a "paste" event. I've tried to put the same code in a button click event, but with no luck. What am I missing here?
Here's my jsfiddle
If possible please tell me how I can do the same in IE(10 & above) & Mozilla Firefox.
Exapmle : Demo Applet
As mozdev states, this feature should be available in FF since version 22.
https://developer.mozilla.org/en-US/docs/Web/Events/paste
"Caniuse" states that too btw: http://caniuse.com/#feat=clipboard
Maybe you have to use a browser prefix or the event attributes have different names. Is your event not fired in other browser than chrome or is it fired but you don't receive data?
EDIT:
Additionally 'paste' is an event, you can't trigger it manually by a button. (Well you can but it doesn't make any difference.) This wouldn't make sense because you can't directly access the clipboard for security reasons and therefore you don't have the data available. in browser. With a button you have to use the file-select and upload method, which i think needs a webserver in the back to handle the request, so no pure js solution.