Skip to content

Instantly share code, notes, and snippets.

@allthesignals
Created January 17, 2020 23:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save allthesignals/a05d1b9439115eb990bae148301bcaed to your computer and use it in GitHub Desktop.
Save allthesignals/a05d1b9439115eb990bae148301bcaed to your computer and use it in GitHub Desktop.

Goal

I'd like to mock the requests for tiles made by MapboxGL using Pretender.

Problem

Pretender doesn't intercept those requests

What I've discovered

I think MapboxGL uses service workers. I'm not sure because I can't see them in the Chrome inspector, even on production sites. When I log the XMLHttpRequest global — which PretenderJS is responsible for replacing with a FakeRequest object — it always appears to be the native code.

I think this has to do with how the service worker scope works. It seems like its own fetch interface isn't being replaced by Pretender.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment