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

Support sendBeacon #249

Open
jackson-dean opened this issue Feb 25, 2019 · 5 comments
Open

Support sendBeacon #249

jackson-dean opened this issue Feb 25, 2019 · 5 comments

Comments

@jackson-dean
Copy link

I have a request being sent using the native sendBeacon api which pretender does not intercept. Is this something that should/could be added? Or is it already somehow supported and I am just missing something?

@xg-wang
Copy link
Member

xg-wang commented Feb 25, 2019

I believe it doesn't

@xg-wang xg-wang changed the title Does pretender support sendBeacon? Support sendBeacon Sep 16, 2019
@xg-wang
Copy link
Member

xg-wang commented Sep 16, 2019

sendBeacon should be polyfillable by a POST xhr

@Aaronius
Copy link

We could really use this as well. @xg-wang I don't think I quite understand your last comment. Could you provide more context? If it's something relatively simple to do I may be able to help out.

@xg-wang
Copy link
Member

xg-wang commented Oct 23, 2020

@Aaronius My idea was we can include a small polyfill of let sendBeacon xhr under the hood, then the beacon can go through pretender's fake xhr. We might also need to set the 64kb limit when calling sendBeacon synchronously.
One thing I haven't thought is how to properly test those beacon outlive the document.

@xg-wang
Copy link
Member

xg-wang commented Apr 24, 2021

@jackson-dean @Aaronius thinking more on this, how do you think about something like this, and what else would you like to add?

const beaconHandler = server.sendBeacon('/api/beacon', true /* sendBeacon can only return boolean */);
beaconHandler.returns(false); // can control the return value
beaconHandler.numberOfCalls; // has same `numberOfCalls` as regular handlers
beaconHandler.async === false; // always sync 

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

No branches or pull requests

3 participants