question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Why leaflet needs to add invisible pixel on page?

See original GitHub issue

How to reproduce

  • Leaflet version I’m using: 1.3.1
  • Browser (with version) I’m using: Chrome 65
  • OS/Platform (with version) I’m using: Win10
  • step 1: Enable Strict CSP policy
  • step 2: Load the page with leaflet library and map.

What behaviour I’m expecting and which behaviour I’m seeing

No errors.

Leaftlet wants to add image like this

data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs=

this is the code in minified file that adds it

    var Qt = Object.create || function() {
        function t() {}
        return function(i) {
            return t.prototype = i,
            new t
        }
    }()
      , ti = 0
      , ii = /\{ *([\w_-]+) *\}/g
      , ei = Array.isArray || function(t) {
        return "[object Array]" === Object.prototype.toString.call(t)
    }
      , ni = "data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs="
      , oi = 0
      , si = window.requestAnimationFrame || p("RequestAnimationFrame") || m
      , ri = window.cancelAnimationFrame || p("CancelAnimationFrame") || p("CancelRequestAnimationFrame") || function(t) {
        window.clearTimeout(t)
    }

Why? before I make an exception for this I want to know why leaflet needs to add invisible pixel.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6

github_iconTop GitHub Comments

2reactions
ghybscommented, Mar 31, 2018

Hi,

A possible workaround would be to provide your own “empty” / dummy image that you can whitelist, and replace Leaflet’s emptyImageUrl value by the path to that image.

Unfortunately since Leaflet is built by rollup, it is much more difficult to modify this value while using the officially built file. You now have to override all methods that use this value (2x in GridLayer and 1x in TileLayer).

Live demo: https://plnkr.co/edit/vJc0QNqMozn6EQqypR9E?p=preview

It uses an “emptyImage.gif” file which path is referenced in the 3 overridden methods in modifyEmptyImageUrl.js script.

0reactions
techsincommented, Apr 1, 2018

@cherniavskii that kinda defeats the purpose of csp policy though. But I do get that’s it’s a trade and an option.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Pixel transparency in Leaflet ImageOverlay?
Is it possible to set one or a range of colors as transparent in raster imageOverlays in Leaflet? leaflet · Share.
Read more >
Making leaflet handle tiles that have nodata values ...
Obviously the "easiest" solution would have been to set your "no data" areas as transparent pixels in your tile set in the first...
Read more >
Leaflet - a JavaScript library for interactive maps
The central class of the API — it is used to create a map on a page and ... tapTolerance, Number, 15, The...
Read more >
Spy pixel
Spy pixels or tracker pixels are hyperlinks to remote image files in HTML email messages that have the effect of spying ... the...
Read more >
Digital Signage: Guidelines for Flyers – Duke Divinity School
If you use a phone number, be sure to include the area code. II. SIZE. All flyers to be posted on digital signage...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found