Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adds support to utilize service workers to see network response for mocked requests #351

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

gabrielcsapo
Copy link

fixes #287

This is the demo code I ran to get some output from my experiment

<!DOCTYPE html>
<head>
  <meta charset="UTF-8">
  <title>Pretenderjs</title>
</head>
<body>
  <script src="./dist/pretender.bundle.js"></script>
  <script>
    (async function() {
      const server = new Pretender(function() {
        this.get('/hello-world', request => [200, {}, "hello world!"]);
      });

      server.unhandledRequest = function(verb, path, request) {
        console.log(verb, path, request);
      }
      
      await fetch('/hello-world');
    }())
  </script>
</body>
</html>

Screen Shot 2022-06-09 at 11 38 29 PM

Screen Shot 2022-06-09 at 11 38 30 PM

unhandled requests work as well!

<!DOCTYPE html>
<head>
  <meta charset="UTF-8">
  <title>Pretenderjs</title>
</head>
<body>
  <script src="./dist/pretender.bundle.js"></script>
  <script>
    (async function() {
      const server = new Pretender(function() {
        this.get('/hello-world', request => [200, {}, "hello world!"]);
      });

      server.unhandledRequest = function(verb, path, request) {
        console.log('unhandledRequest', verb, path, request);
      }
      
      await fetch('/hello-world');
      await fetch('/hello');
    }())
  </script>
</body>
</html>

Screen Shot 2022-06-09 at 11 45 40 PM

@gabrielcsapo gabrielcsapo marked this pull request as ready for review November 15, 2022 19:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Intercept XMLHttpRequest through a Service Worker
1 participant