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

Bug: Fails in Chrome Extensions #202

Closed
liaxei opened this issue Jan 1, 2023 · 3 comments
Closed

Bug: Fails in Chrome Extensions #202

liaxei opened this issue Jan 1, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@liaxei
Copy link

liaxei commented Jan 1, 2023

Describe the bug
tslog fails if used in Manifest V3 Chrome Extensions. More specifically it fails in background pages which now use service workers. The reason is that service workers do not have a window object. So the following code in tslog/dist/esm/runtime/browser/index.js fails:
const meta = { runtime: "Browser", browser: window?.["navigator"].userAgent, };

To Reproduce
Steps to reproduce the behavior:

  1. Create a basic Chrome Extension
  2. Add tslog to a background script
  3. Load the unpacked extension to your Chrome. To do that turn on the Developer mode on Extensions page.
  4. Click on the "background page" link on your extension on Extensions page to open DevTools
  5. Check the error in the Console of DevTools

Expected behavior
Extension should not fail.

Screenshots
image

Solution
Use self if window is not defined.

@liaxei liaxei added the bug Something isn't working label Jan 1, 2023
@terehov
Copy link
Contributor

terehov commented Jan 1, 2023

MR is welcome.
Otherwise an explanation how to create a basic chrome extension.

@liaxei
Copy link
Author

liaxei commented Jan 2, 2023

@terehov I have created a chrome extension for you to play with https://github.com/liaxei/dummy-chrome-extension

@terehov
Copy link
Contributor

terehov commented Mar 2, 2023

Check out V4.8.0.

@terehov terehov closed this as completed Mar 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants