Skip to content

Commit

Permalink
add comments on Cloudflare workers
Browse files Browse the repository at this point in the history
  • Loading branch information
KonnorRogers committed Nov 24, 2022
1 parent ff23483 commit 2f29217
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
10 changes: 8 additions & 2 deletions packages/js/src/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,18 @@ class Honeybadger extends Client {

constructor(opts: Partial<Types.BrowserConfig> = {}) {
const global = globalThisOrWindow();
let projectRoot = ""

// Cloudflare workers do not have access to location API.
if (global.location != null) {
projectRoot = global.location.protocol + '//' + global.location.host
}

super(
{
async: true,
maxErrors: null,
// @TODO: Cloudflare workers do not have access to location API.
projectRoot: global.location.protocol + '//' + global.location.host,
projectRoot,
...opts,
},
new BrowserTransport()
Expand Down
11 changes: 8 additions & 3 deletions packages/js/src/browser/integrations/breadcrumbs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,9 @@ export default function (_window = globalThisOrWindow()): Types.Plugin {
},
});
},
// @TODO: In CloudFlare workers this must be false.
true
// In CloudFlare workers this must be false. This is a hacky way to detect it.
// CF workers require useCapture to be false.
_window.location ? true : false
);
})();

Expand Down Expand Up @@ -269,8 +270,12 @@ export default function (_window = globalThisOrWindow()): Types.Plugin {
return;
}

if (_window.location == null) {
// Most likely in a CF worker, we should be listening to fetch requests.
return
}

// The last known href of the current page
// @TODO: Cloudflare workers do not have access to location API.
let lastHref = _window.location.href;

function recordUrlChange(from, to) {
Expand Down

0 comments on commit 2f29217

Please sign in to comment.