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: add window / document checks, refactor XMLHttpRequest to Fetch #958

Merged
merged 1 commit into from Dec 7, 2022

Conversation

KonnorRogers
Copy link
Collaborator

@KonnorRogers KonnorRogers commented Nov 23, 2022

Status

** Ready **

Description

Reduce our calls to windows object, use fetch instead of XMLHTTPRequest, and other niceties to allow Chrome Extensions and WebWorkers to use Honeybadger.

Related Issues

#686
#956

Todos

  • Tests
  • Documentation
  • Changelog Entry (unreleased)

Additional notes

In some light testing of cloudflare workers I discovered the following:\

  • "document", "window", and the "Location API" are not present.
  • catching things like onunhandledpromiserejection doesn't actually work.

Example:

Honeybadger.configure({
 // ...
})

export default {
  async fetch(): Promise<Response> {
     throw Error("im an error")
     return new Response("Hello World!");
  },
};

The above will just straight up error and it doesnt get caught by honeybadger.

There are some docs on handling errors in CF workers, but they feel rather manual and I havent seen anything about catching global errors.

https://developers.cloudflare.com/workers/learning/logging-workers/

Happy to do some more digging, but you can at least call Honeybadger.notify() from a CF worker and it wont error.

export default {
  async fetch(): Promise<Response> {
    Honeybadger.notify()
  },
};

@KonnorRogers KonnorRogers changed the title fix: webworker compatibiltiy [WIP] fix: webworker compatibiltiy Nov 23, 2022
@KonnorRogers KonnorRogers changed the title [WIP] fix: webworker compatibiltiy fix: webworker compatibility [WIP] Nov 23, 2022
@KonnorRogers KonnorRogers force-pushed the konnorrogers/background-worker-compatibility branch from 00149df to b397581 Compare November 24, 2022 14:21
@KonnorRogers KonnorRogers changed the title fix: webworker compatibility [WIP] fix: remove dependency on document and window objects. [WIP] Nov 25, 2022
@KonnorRogers KonnorRogers force-pushed the konnorrogers/background-worker-compatibility branch from 2f29217 to 9dac42a Compare November 25, 2022 14:58
packages/core/src/types.ts Outdated Show resolved Hide resolved
packages/js/src/browser.ts Outdated Show resolved Hide resolved
packages/js/src/browser.ts Outdated Show resolved Hide resolved
packages/js/src/browser/integrations/breadcrumbs.ts Outdated Show resolved Hide resolved
@subzero10
Copy link
Member

Hey @KonnorRogers, I started going through the PR (I know it's not ready, just wanted to have an idea) but it's difficulty to follow with all the formatting changes. Can you please remove the changed semi-colons and we can decide on a convention at a different PR?

@KonnorRogers
Copy link
Collaborator Author

@subzero10 Was already looking at fixing the diff to be easier to follow 🙈

@subzero10
Copy link
Member

@subzero10 Was already looking at fixing the diff to be easier to follow 🙈

Awesome, thanks! I will come back to this later then 😄

@KonnorRogers
Copy link
Collaborator Author

@subzero10 should be much easier to parse now.

@KonnorRogers KonnorRogers force-pushed the konnorrogers/background-worker-compatibility branch from c06b7fc to 5a261a8 Compare November 25, 2022 16:29
@KonnorRogers KonnorRogers changed the title fix: remove dependency on document and window objects. [WIP] fix: remove dependency on document and window objects. Nov 25, 2022
@KonnorRogers KonnorRogers changed the title fix: remove dependency on document and window objects. fix: remove dependency on document and window objects Nov 25, 2022
@subzero10 subzero10 added the js @honeybadger-io/js label Nov 26, 2022
@KonnorRogers KonnorRogers force-pushed the konnorrogers/background-worker-compatibility branch 2 times, most recently from ce1bcfc to 7be35e2 Compare November 28, 2022 03:02
subzero10
subzero10 previously approved these changes Nov 30, 2022
Copy link
Member

@subzero10 subzero10 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work!
Did you get a chance to also test manually? What did you test with (i.e. browser, nodejs, chrome extension, web worker)?
I think it's necessary here because our integration tests mock the http call, which is something that we are changing with the PR.

packages/core/src/types.ts Outdated Show resolved Hide resolved
packages/js/jest-browser-setup.js Outdated Show resolved Hide resolved
packages/js/src/browser/transport.ts Outdated Show resolved Hide resolved
packages/js/test/integration/worker.js Show resolved Hide resolved
packages/js/test/unit/browser.test.ts Show resolved Hide resolved
@KonnorRogers
Copy link
Collaborator Author

Great work! Did you get a chance to also test manually? What did you test with (i.e. browser, nodejs, chrome extension, web worker)? I think it's necessary here because our integration tests mock the http call, which is something that we are changing with the PR.

I did get a chance to test manually in the following environments:

  • Chrome Extension
  • Browser
  • Web Worker
  • Cloudflare worker

I basically tested that Honeybadger.configure() and Honeybadger.notify() didnt produce errors and were able to send reports.

I did not test NodeJS since I didnt touch anything in core or in server.

@subzero10
Copy link
Member

Great work! Did you get a chance to also test manually? What did you test with (i.e. browser, nodejs, chrome extension, web worker)? I think it's necessary here because our integration tests mock the http call, which is something that we are changing with the PR.

I did get a chance to test manually in the following environments:

  • Chrome Extension
  • Browser
  • Web Worker
  • Cloudflare worker

I basically tested that Honeybadger.configure() and Honeybadger.notify() didnt produce errors and were able to send reports.

I did not test NodeJS since I didnt touch anything in core or in server.

Sounds great! Yeah I don't see a reason to manually test server-side. We are good to go then!

subzero10
subzero10 previously approved these changes Dec 2, 2022
@subzero10
Copy link
Member

@KonnorRogers Btw, I think this is more of a feature rather than a fix. What do you think?

@KonnorRogers
Copy link
Collaborator Author

Id agree with feature here.

@KonnorRogers KonnorRogers changed the title fix: remove dependency on document and window objects feat: remove dependency on document and window objects Dec 2, 2022
@KonnorRogers
Copy link
Collaborator Author

Fun reminder of how annoying this problem is with detecting where a library is being called from:

https://twitter.com/TkDodo/status/1598992656226344960

https://twitter.com/alexdotjs/status/1598996196357738497

Refactor `XMLHttpRequest` in `send` to use `fetch`

update transport tests

fix test suite

fix linting issues

fix linting issues

downgrade jest version number

package downgrade

fix test suite

cleanup comment

fix package version

linting

add comments on Cloudflare workers

add comments on Cloudflare workers

fix references to document

ts-standard for easier diff

remove async option

working on diffs

working on diffs

working on diffs

working on diffs

working on diffs

remove async

one more time

tests: add worker tests

tests: add worker tests

tests: add worker tests

use jasmine

use jasmine

remove jasmine from worker

remove jasmine from worker

one last try

circumvent fetch

add some suggestions
@KonnorRogers KonnorRogers force-pushed the konnorrogers/background-worker-compatibility branch from aa2ca1d to 1941244 Compare December 6, 2022 23:11
@KonnorRogers KonnorRogers changed the title feat: remove dependency on document and window objects feat: add window / document checks, refactor XMLHttpRequest to Fetch Dec 6, 2022
@KonnorRogers KonnorRogers enabled auto-merge (squash) December 7, 2022 00:01
@KonnorRogers KonnorRogers merged commit b7e717f into master Dec 7, 2022
@thatsmydoing
Copy link

Given the switch to using fetch that means IE is fully unsupported, should there be a list of supported browsers / runtimes in the README or documentation?

@subzero10
Copy link
Member

Given the switch to using fetch that means IE is fully unsupported, should there be a list of supported browsers / runtimes in the README or documentation?

Actually, there is a page in our docs, but it's outdated (it says that IE 11 is supported).
We will update it and probably create a table with more details on supported versions per browser.

Thank you for pointing it out!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
js @honeybadger-io/js
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants