mapbox-gl-js icon indicating copy to clipboard operation
mapbox-gl-js copied to clipboard

Add "noopener" to links

Open jedgar1mx opened this issue 5 years ago • 8 comments

Motivation

Improve lighthouse best practice score.

Implementation

Add the "noopener" to <a href="https://www.mapbox.com/about/maps/" target="_blank">© Mapbox</a> and <a href="http://www.openstreetmap.org/about/" target="_blank">© OpenStreetMap</a> within the control section.

jedgar1mx avatar Feb 07 '20 03:02 jedgar1mx

Good idea! Would you like to submit a pull request for this?

mourner avatar Feb 07 '20 16:02 mourner

@mourner Is it possible to submit a PR? These come from the TileJSON from the Tileset API, the HTML is passed straight through as is to the AttributionControl.

andrewharvey avatar Feb 08 '20 09:02 andrewharvey

@andrewharvey @mourner There's an old closed ticket for this issue that explicitly says that they can't be changed on the client side. We'd have to generate these links in GL JS to allow this feature https://github.com/mapbox/mapbox-gl-js/issues/4591#issuecomment-350911996

ryanhamley avatar Feb 10 '20 18:02 ryanhamley

Ah, right. We could either add rel=noopener to all links after every attribution update dynamically, or find out if we could change it in the maps API.

mourner avatar Feb 10 '20 18:02 mourner

Hi @mourner @ryanhamley I have a customer that would really appreciate this update if possible. They get a "ding" on their Google lighthouse scores because of this, and they do not see an update in v2.

Direct quote:

"I can see that in Mapbox GL 2.0, the rel="noopener nofollow" gets added to the logo and the "improve this map" links - I think that's new - but still missing from the Maxar/OSM/Mapbox copyright links."

SWRB avatar Dec 16 '20 17:12 SWRB

Hi @SWRB as mentioned in previous comments, these links aren't generated in the client. I've alerted our API team to this request though. If I get any updates from them, I'll provide them here.

ryanhamley avatar Dec 16 '20 19:12 ryanhamley

thanks @ryanhamley for the clarification, my guess is no update from our API team here?

SWRB avatar Jan 08 '21 16:01 SWRB

The following actually works...

const map = new Map({
    container: '...',
    style: '...',
    attributionControl: false,
});

class CustomAttributionControl extends AttributionControl {
    _updateAttributions(...args: any[]) {
        const res = (super._updateAttributions as any)(...args);

        Array.from(document.querySelectorAll('.maplibregl-ctrl-attrib a')).forEach(item => item.setAttribute('rel', 'nofollow noreferrer'));

        return res;
    }
}

const attributionControl = new CustomAttributionControl({
    compact: true,
});

Would be nice however to have access to this hook without overriding a private method.

smnbbrv avatar Oct 31 '22 19:10 smnbbrv