Issue metadata
Sign in to add a comment
|
addEventListener click doesn't work for button === 1 (middle mouse click)
Reported by
willalwa...@gmail.com,
May 14 2016
|
||||||||||||||||||||||
Issue description
UserAgent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2735.0 Safari/537.36
Steps to reproduce the problem:
1. add this code to content_script of some extension
document.addEventListener("click", function(e) {
if (e.button === 1 ) {
console.log("hello");
}
});
2. when you middle click on some LINKs/URLs you won't see "hello" message in the console
What is the expected behavior?
What went wrong?
can't get any response of middle clicks (button === 1 using "click" listener)
WebStore page:
Did this work before? Yes It works now in Stable versions, mb also in Beta & Dev - click on links/urls and you'll see the message
Chrome version: 52.0.2735.0 Channel: canary
OS Version: 10.0
Flash Version: Shockwave Flash 22.0 r0
,
May 15 2016
youtube.com - works great with stable version of Chrome, but not with Canary
,
May 15 2016
Which link? If it's difficult to explain in words, take a screenshot and mark the link that should be clicked.
,
May 15 2016
It is not specific to links, the following minimal test case also shows the problem.
1. Open data:text/html,<script>document.addEventListener('click',function(e){alert(e.button)})</script>
2. Use the scroll wheel to click.
3. Expect a dialog that shows "1" (on Canary nothing is shown).
I did a bisect (https://www.chromium.org/developers/bisect-builds-py) and got:
You are probably looking for a change made after 390188 (known good), but no later than 390199 (first known bad).
CHANGELOG URL:
https://chromium.googlesource.com/chromium/src/+log/5433e667fc2a2a1e62e969a8d7539081c4dde9c3..94d5fad34f0351e61fd658ca4ed93648c415620d
Suspect: 76fea00a18f75886ea649414393228180306e13d ( bug 255 ).
This change seems intentional...
,
May 16 2016
Yes. The change was technically intentional to make Chrome inline with the spec and other browsers like FF. Regarding the websites posted, can you explain a little more where to middle click and what to expect that it doesn't work in Canary?
,
May 16 2016
#6 I added steps to reproduce in #5. Open the following URLs and use the mouse wheel to click on the link. data:text/html,<a onclick="event.preventDefault()" href="javascript:alert(1)">Test</a> data:text/html,<a onmousedown="event.preventDefault()" href="javascript:alert(1)">Test</a> data:text/html,<a onmouseup="event.preventDefault()" href="javascript:alert(1)">Test</a> In the last two cases, the dialog always pops up (before and after your fix to issue 255 ). In the first example, the dialog does not show up in Chrome stable (M-50) (as expected), but the dialog unexpectedly shows up in Canary (M-52) (i.e. the default click action was not blocked). What the reporter actually wants is to prevent the link from being opened in a new tab when the mousewheel is used for clicking.
,
May 16 2016
How does he do that right now in FireFox?
,
May 16 2016
Afaik not; He built a Chrome extension which used to work until bug 255 was fixed. It might be a good idea to check with other vendors on how they intend to solve this issue.
,
May 16 2016
Is the extension now published? Do you know the name of the extension?
,
May 16 2016
"How does he do that right now in FireFox? - It actually works in Firefox. I've developed the same extension also for Firefox
,
May 16 2016
#11 Then it'd be nice if you share how you did it, since none of the above three test cases (comment 7) work.
,
May 16 2016
It's same as in first comment:
addEventListener("click", function(e) {
if (e.button === 1 && e.target.closest("a") != null) {
e.preventDefault();
e.stopPropagation();
});
,
May 16 2016
How come? I just tested that and they were not firing click event for button == 1. Here is my example: https://output.jsbin.com/porezi I tested with FF 45.0 on Mac. Can you elaborate a bit more and what you see?
,
May 16 2016
This works, indeed:
data:text/html,<a href="javascript:alert(1)">Test</a><script>addEventListener("click", function(e) {e.preventDefault();})</script>
It appears that in Firefox, the click event is dispatched on document and bubbles up to window:
data:text/html,<script>window.onclick = function(e){alert(e.button);}</script>Alert
data:text/html,<script>document.onclick = function(e){alert(e.button);}</script>Alert
data:text/html,<script>document.body.onclick = function(e){alert(e.button);}</script>No alert
,
May 16 2016
Yeah. But it doesn't dispatch it to the elements inside. I need to investigate a bit more with other vendors and see why they do that. I'll probably revert the original change of suppressing click event for button==1 for now.
,
May 20 2016
#16 "I'll probably revert the original change of suppressing click event" Please answer when you decide what you are going to do with it. And if you not going to revert it, I'd like to know why? Because as we found out it works in FF - "The change was technically intentional to make Chrome inline with the spec and other browsers like FF" - and why the spec requires its removing?
,
May 20 2016
Reposting #18 with the correct links: I forgot to update this issue. We talked about this and decided not to revert it for now. We would like this to hit beta and see if it causes any more issues like this. Regarding the spec, here is the link to the spec: https://www.w3.org/TR/DOM-Level-3-Events/#event-type-click as it's stated the click event should only be fired for primary button of the mouse. Regarding the history of it you can have a look at issue 255 . I understand that the change will remove the functionality to prevent the browser to open a new tab and we are working on a workaround for that. But in the meantime if you only need the actual event I believe you can use the following workaround: var middleButtonMouseDownTarget = null; document.addEventListener('mousedown', function(e) { if (e.button == 1) { middleButtonMouseDownTarget = e.target; } }, true); document.addEventListener('mouseup', function(e) { if (e.button == 1) { if (e.target == middleButtonMouseDownTarget) e.target.dispatchEvent(new MouseEvent('click', e)); middleButtonMouseDownTarget = null; } }, true); Also is it possible for you to use another control instead of (Ctrl/Shift + middle click) which I believe is not reliable as you see from the spec anymore.
,
May 21 2016
#19 "if you only need the actual event" yeah I know it's not a problem if I don't need "prevent default" "we are working on a workaround for" ok, thank you for the info
,
Jun 1 2016
Moving this nonessential bug to the next milestone. For more details visit https://www.chromium.org/issue-tracking/autotriage - Your friendly Sheriffbot
,
Jun 8 2016
I'm going to close this for now. Hopefully we can work on this soon: https://discourse.wicg.io/t/new-event-for-non-primary-button-click/1527
,
Jun 13 2016
Hi Navid, It has been two weeks since the last message on that thread. Can you try to ensure that there is a good alternative to catching and blocking middle-click events before the 'click' event disappears? I predict that if Chrome lands in its current state, that you will receive bug reports for a few months. At least, that is what happened when I fixed Chrome's behavior of the :focus pseudo-class on anchor tags ( bug 388666 ). In my case, developers and users are able to fix their websites to get the desired effect. But in your case, devs/users currently have no way to get their desired (=previous) behavior. The new click behavior is indeed standards-compliant (and like IE / Edge), but inconsistent with Firefox and Safari. Safari is like the old Chrome, and Firefox fires the click event for listeners on document and window (this allows pages and add-ons to change the behavior for middle-click). PS. I've changed the status from Fixed to WontFix because the reported issue was not fixed, but deemed "working as intended".
,
Jun 13 2016
Hi Rob, I'll wait until the end of June and then I will discuss with others what the best course of action is in this case based on the number of reports we will get. I'll have a close eye on this issue.
,
Jun 21 2016
,
Sep 8 2016
The "click" event is no longer dispatched for non-primary buttons as per UI events spec. This will ensure the pages that don't check the buttons attribute on their click handlers don't show unexpected behaviors when middle clicking for example. Instead there will be new event "auxclick" event for non-primary buttons that will be useful for some apps that truly care about click action for non-primary buttons. For example in case someone wants to prevent opening a new tab when middle clicking a link or adobt any other actions on click behavior of any non-primary button. Here is the spec for the event and some examples: https://navidz.github.io/auxclick/
,
Sep 8 2016
Great, thanks for this information. Will it be integrated successively Canary->Beta->Stable or at once for all?
,
Sep 8 2016
It is targeted for Chrome 55. So right now it is in Canary. It should be in dev by the end of the week or early next week. The beta 55 will come out on sometime around October and will hit stable around November. Until then we can fix any other issues that may come up and also give the website enough time to adapt I believe.
,
Sep 9 2016
If you want to listen to only non-primary clicks then yes. But if you like to listen to both primary click and non-primary ones then you need to have your handler to handler both of the events.
,
Sep 9 2016
Yeah, works in Canary (but had to update it first)
,
Oct 5 2016
|
|||||||||||||||||||||||
►
Sign in to add a comment |
|||||||||||||||||||||||
Comment 1 by rob@robwu.nl
, May 15 2016Labels: Needs-Feedback