Skip to content

Detect Web Workers environment #12

@grz0zrg

Description

@grz0zrg

When the library is used in a web worker there is an issue with undefined window so i suggest adding Web Workers detection such as :

// Environment detection
if (typeof module === "object" && module && typeof module.exports === "object") {
	// Node.js
	module.exports = msgpack;
}
else if (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope) {
	// Global object
	self[self.msgpackJsName || "msgpack"] = msgpack;
} else {
	// Global object
	window[window.msgpackJsName || "msgpack"] = msgpack;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions