Hi! 👋
Firstly, thanks for your work on this project! 🙂
Today I used patch-package to patch tslog@4.7.5 for the project I'm working on.
'window' does not work on WebWorkers, 'globalThis' has been available pretty much everywhere (browsers AND Node) for about four years.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis#browser_compatibility
https://caniuse.com/?search=globalThis
Here is the diff that solved my problem:
diff --git a/node_modules/tslog/dist/esm/runtime/browser/index.js b/node_modules/tslog/dist/esm/runtime/browser/index.js
index adae196..b33903d 100644
--- a/node_modules/tslog/dist/esm/runtime/browser/index.js
+++ b/node_modules/tslog/dist/esm/runtime/browser/index.js
@@ -3,7 +3,7 @@ import { formatWithOptions } from "./util.inspect.polyfil.js";
import { jsonStringifyRecursive } from "./helper.jsonStringifyRecursive.js";
const meta = {
runtime: "Browser",
- browser: window?.["navigator"].userAgent,
+ browser: globalThis?.["navigator"].userAgent,
};
const pathRegex = /(?:(?:file|https?|global code|[^@]+)@)?(?:file:)?((?:\/[^:/]+){2,})(?::(\d+))?(?::(\d+))?/;
export function getMeta(logLevelId, logLevelName, stackDepthLevel, hideLogPositionForPerformance, name, parentNames) {
@@ -29,7 +29,7 @@ export function getErrorTrace(error) {
}, []);
}
function stackLineToStackFrame(line) {
- const href = window.location.origin;
+ const href = globalThis.location.origin;
const pathResult = {
fullFilePath: undefined,
fileName: undefined,
This issue body was partially generated by patch-package.
Hi! 👋
Firstly, thanks for your work on this project! 🙂
Today I used patch-package to patch
tslog@4.7.5for the project I'm working on.'window' does not work on WebWorkers, 'globalThis' has been available pretty much everywhere (browsers AND Node) for about four years.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis#browser_compatibility
https://caniuse.com/?search=globalThis
Here is the diff that solved my problem:
This issue body was partially generated by patch-package.