You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 12, 2025. It is now read-only.
Repository navigation
This repository was archived by the owner on Aug 12, 2025. It is now read-only.
enableAutoOutboundTracking breaks target="_blank" and probably noopener security #12
When loading plausible with link tracking, links with target _blank are no longer opened in a new tab.
Expected behavior
Instead, the link should open in a new tab.
Steps to reproduce
Steps:
Install normally
Set it up
Enable enableAutoOutboundTracking
importPlausiblefrom'plausible-tracker'constplausible=Plausible({domain: 'example.com',trackLocalhost: true})// This tracks the current page view and all future ones as wellplausible.enableAutoPageviews()plausible.enableAutoOutboundTracking()
Click on the button. The page opens in the same tab, not in a new tab
Your Environment
OS: Mac
Browser: Safari, Chrome, (probably all)
Versions: all
Additional context
Might also be interesting to check if the rel attributes are respected (noopener) from a security perspective.
Reacted by Joel L., Ross Rosario, Matthias Hilger, Sam Levy, albi.eth, Maxime Dupré, Asbjørn Ottesen Steinskog, Paul Schreiber, Jose Buitron, Daniel Becker and 10 more
Also, an issue we had on the main tracker script was middle clicking on the mouse to open the link in a new tab. Outbound link tracking was messing with the default behaviour there which was fixed. Is this issue also present in this tracker script?
Okay great! To prevent all the special cases for each browser, it might be an idea to update the way you delay the click event. If you redispatch the event, you don't need to check on shift keys, middle mouse etc.
BTW, the current behaviour in plausible does stop noopener when not using target="blank"
Darn, yeah that's true.
I do like the idea of just falling back to browser defaults as much as possible. Your demo is great, thanks for that. However, middle clicking and shift-clicking does not open the link in a new tab for me :/ Running FireFox on Elementary OS.
BTW, the current behaviour in plausible does stop noopener when not using target="blank"
Darn, yeah that's true.
I do like the idea of just falling back to browser defaults as much as possible. Your demo is great, thanks for that. However, middle clicking and shift-clicking does not open the link in a new tab for me :/ Running FireFox on Elementary OS.
Oh too bad, does work on Chrome and Safari on MacOS.
Firefox on Elementary: middle click nor ctrl-click work to open in a new tab
Chromium on Elmentary: middle click does not work, ctrl-click does work
The only thing I can think of is the second time the event is dispatched, it has isTrusted: false. I wonder if there's some security feature in the browser that doesn't allow JS to trigger a new tab link click programmatically. I didn't find much information about why it would be prevented.
Thanks @SimonBackx for making this demo, it's great. But I cannot merge it since it doesn't work consistently everywhere.
I think the best solution is switching to navigator.sendBeacon to send the event itself. That way we don't need to mess with the browser event at all, we can leave everything as default browser behaviour but still get the desired result of sending the event to our backend. What do you think?
Not sure if this belongs here, but enableAutoOutboundTracking also broke an interactive site of ours: We had a simple anchor (without href) with onclick event handler attached. The event handler would trigger the opening of a modal. After clicking the link, however, the entire page would reload, killing the modal that was just opening again. Assume this line to be the culprit:
Hey @metmarkosaric! Since the package doesn't get updated regularly, do you think you can make @Barbapapazes the maintainer of this package and let him update it? It seems like his package is much better than the original one!
Huh, it looks a bugs is just does not matter for Plausible team.
This bug is opened 4 years ago, have a lot of comments, even couple PRs and still had not been fixed.
Huh, it looks a bugs is just does not matter for Plausible team.
This bug is opened 4 years ago, have a lot of comments, even couple PRs and still had not been fixed.
Yeah, believe it or not, I stopped using and recommending Plausible because of this trivial issue. I use the fixed fork on legacy instances that still use it.
@orvn@SimonBackx i love plausible, but it looks current package are rusty and not actively maintain anymore, because they did not merge pull request with fix already 4 years.
So i have re-implemented analytics client, now it does not block a user clicks, works fine with target="_blank" and send analytics well even for static sites (like sites built with Astro), because uses modern browser API (that is enough mature and widely available now).
@Barbapapazes it does make sense. However i just checked your solution and as i see in the code of your implementation - there are not resolved a problem with events loss for static sites (since this solution uses fetch with no keepalive), and this solution still uses legacy code style based on callbacks instead of modern Promise API.
Hey! Karl from Plausible here. We've recently rewritten our tracking library to share the same codebase for both the NPM library and web snippet, keeping both up to date. The new NPM library can be found here: https://www.npmjs.com/package/@plausible-analytics/tracker
The new library doesn't have the reported problem.
Caution that we're not yet at a 1.0.0 release - this will be happening in the upcoming weeks-months. Do share feedback under the main repo.
Activity
[-]enableAutoOutboundTracking breaks target="_blank" [/-][+]enableAutoOutboundTracking breaks target="_blank" and probably noopener security[/+]ukutaht commentedon Apr 12, 2021
Yes, the timeout in
plausible-tracker/src/lib/tracker.ts
Line 286 in a5f8e94
target="_blank".For
target="_blank"links, browser default behaviour should be allowed to happen as we do in our main tracker script here: https://github.com/plausible/analytics/blob/master/tracker/src/plausible.js#L87ukutaht commentedon Apr 12, 2021
Also, an issue we had on the main tracker script was middle clicking on the mouse to open the link in a new tab. Outbound link tracking was messing with the default behaviour there which was fixed. Is this issue also present in this tracker script?
SimonBackx commentedon Apr 13, 2021
I'm not sure but shouldn't you also replace the
location.href = link.href;with something that respects the rel and target attributes?https://dev.to/dhilipkmr/why-should-you-use-noopener-beware-of-security-flaws-3i57
ukutaht commentedon Apr 13, 2021
When using
target="_blank", we just allow the default browser behaviour. This line:location.href = link.href;does not run when using
target="_blank". So it already respectstarget="_blank" rel="noopener"links.SimonBackx commentedon Apr 13, 2021
Okay great! To prevent all the special cases for each browser, it might be an idea to update the way you delay the click event. If you redispatch the event, you don't need to check on shift keys, middle mouse etc.
I've made an example
https://github.com/SimonBackx/link-delay-test
Demo at https://simonbackx.github.io/link-delay-test/
SimonBackx commentedon Apr 13, 2021
BTW, the current behaviour in plausible does stop noopener when not using
target="blank"ukutaht commentedon Apr 13, 2021
Darn, yeah that's true.
I do like the idea of just falling back to browser defaults as much as possible. Your demo is great, thanks for that. However, middle clicking and shift-clicking does not open the link in a new tab for me :/ Running FireFox on Elementary OS.
SimonBackx commentedon Apr 13, 2021
Oh too bad, does work on Chrome and Safari on MacOS.
ukutaht commentedon Apr 28, 2021
I tested again:
The only thing I can think of is the second time the event is dispatched, it has
isTrusted: false. I wonder if there's some security feature in the browser that doesn't allow JS to trigger a new tab link click programmatically. I didn't find much information about why it would be prevented.Thanks @SimonBackx for making this demo, it's great. But I cannot merge it since it doesn't work consistently everywhere.
I think the best solution is switching to
navigator.sendBeaconto send the event itself. That way we don't need to mess with the browser event at all, we can leave everything as default browser behaviour but still get the desired result of sending the event to our backend. What do you think?SimonBackx commentedon Apr 28, 2021
Yes, the sendBeacon approach seems the right one!
maurice-g commentedon Sep 2, 2021
Not sure if this belongs here, but
enableAutoOutboundTrackingalso broke an interactive site of ours: We had a simple anchor (without href) withonclickevent handler attached. The event handler would trigger the opening of a modal. After clicking the link, however, the entire page would reload, killing the modal that was just opening again. Assume this line to be the culprit:plausible-tracker/src/lib/tracker.ts
Line 288 in a5f8e94
ukutaht commentedon Sep 2, 2021
Thanks for reporting @maurice-g.
I can't see a way to fix it other than moving to a completely different method for tracking like
sendBeaconor something else.maurice-g commentedon Sep 2, 2021
I understand. But I do think this would warrant an entry in the docs to warn users that this function might break functionality.
24 remaining items
Barbapapazes commentedon Feb 3, 2024
Hello,
Since this package have not been update for two years, I made a fork.
I rewrite the tracker to be more modular and I fix this issue.
https://github.com/Barbapapazes/plausible-tracker
cschweda commentedon Mar 1, 2024
Any update on this besides @Barbapapazes new fork (and the fix above from @abett)?
The fix doesn't work for me (under Nuxt 3) -- and I'd like to stick with the canonical plausible instead of a fork.
reatlat commentedon May 28, 2024
Hey @metmarkosaric! Since the package doesn't get updated regularly, do you think you can make @Barbapapazes the maintainer of this package and let him update it? It seems like his package is much better than the original one!
Well done @Barbapapazes!
orvn commentedon Jul 5, 2024
@Barbapapazes, have you considered making a PR into this repo?
Barbapapazes commentedon Jul 5, 2024
@orvn yes but actually, since there is no update, I have no real reason to do it. Also, the fork is a full rewrite so a PR will be difficult.
However, I've been approached by @ukutaht on Twitter but no response since a month so I don't really know what I have to do 🤷♂️
yhabib commentedon Feb 24, 2025
Hi @ukutaht, any updates on this?
fix(analytics): remove automatic outbound link tracking (#6501)
vitonsky commentedon May 9, 2025
Huh, it looks a bugs is just does not matter for Plausible team.
This bug is opened 4 years ago, have a lot of comments, even couple PRs and still had not been fixed.
Isn't it a nice selling point.
chore: disable tracking for outbound links
orvn commentedon May 9, 2025
Yeah, believe it or not, I stopped using and recommending Plausible because of this trivial issue. I use the fixed fork on legacy instances that still use it.
vitonsky commentedon May 10, 2025
@orvn @SimonBackx i love plausible, but it looks current package are rusty and not actively maintain anymore, because they did not merge pull request with fix already 4 years.
So i have re-implemented analytics client, now it does not block a user clicks, works fine with
target="_blank"and send analytics well even for static sites (like sites built with Astro), because uses modern browser API (that is enough mature and widely available now).So you are welcome to try https://github.com/vitonsky/plausible-client
Use plausible as you used to, but with no hassle and with live maintainer 😀
Barbapapazes commentedon May 10, 2025
🙄
cschweda commentedon May 10, 2025
Your fork works great and fixes the issue. Thank you!
vitonsky commentedon May 10, 2025
@Barbapapazes it does make sense. However i just checked your solution and as i see in the code of your implementation - there are not resolved a problem with events loss for static sites (since this solution uses
fetchwith nokeepalive), and this solution still uses legacy code style based on callbacks instead of modern Promise API.All that problems is solved in plausible-client.
Anyway it's cool that Plausible community are live, unlike current repository, and there are developers like you and me who solves a problems.
Let's keep going!
macobo commentedon Aug 12, 2025
Hey! Karl from Plausible here. We've recently rewritten our tracking library to share the same codebase for both the NPM library and web snippet, keeping both up to date. The new NPM library can be found here: https://www.npmjs.com/package/@plausible-analytics/tracker
The new library doesn't have the reported problem.
Caution that we're not yet at a 1.0.0 release - this will be happening in the upcoming weeks-months. Do share feedback under the main repo.