Skip to content

Bug: Fails in Chrome Extensions #202

@liaxei

Description

@liaxei

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions