You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description / Use Case for a Feature
Hello!
Congrats on a fantastic library! I wanted to propose adding support for another type of Javascript runtime environment - service workers. Currently, usage of this library in a non-Node or Browser environment causes reference errors when referring to window. By adding another environment, this logger could be used in serverless environments such as Cloudflare Workers.
I have compiled a version of the library locally that checks for the presence of the importScripts global to determine an additional "serviceworker" environment. I also added the WebWorker lib types to the tsconfig to prevent the Typescript reference error.
constenvironment=()=>{switch(true){case![typeofwindow,typeofdocument].includes("undefined"):
return"browser"case![typeofimportScripts].includes("undefined"):
return"serviceworker"caseObject.prototype.toString.call(typeofprocess!=="undefined" ? process : 0)==="[object process]":
return"nodejs"default:
return"unknown"}}constenv=environment()constisBrowser=env==="browser";constisNode=env==="nodejs"...
My specific usecase is to use this library in a Cloudflare Worker, but I would implement a PR that attempts to be platform-agnostic.
Let me know your thoughts. Thanks!
The text was updated successfully, but these errors were encountered:
Description / Use Case for a Feature
Hello!
Congrats on a fantastic library! I wanted to propose adding support for another type of Javascript runtime environment - service workers. Currently, usage of this library in a non-Node or Browser environment causes reference errors when referring to
window
. By adding another environment, this logger could be used in serverless environments such as Cloudflare Workers.I have compiled a version of the library locally that checks for the presence of the
importScripts
global to determine an additional "serviceworker" environment. I also added theWebWorker
lib types to the tsconfig to prevent the Typescript reference error.My specific usecase is to use this library in a Cloudflare Worker, but I would implement a PR that attempts to be platform-agnostic.
Let me know your thoughts. Thanks!
The text was updated successfully, but these errors were encountered: