Skip to content

Conversation

nikcorg
Copy link

@nikcorg nikcorg commented Sep 20, 2014

When bundling debug using browserify the browser version is used, and the useColors check crashes when in a ServiceWorker, because document, window and navigator are all undefined.

@nikcorg nikcorg changed the title Adds check to useColors for ServerWorker context Adds check to useColors for ServiceWorker context Sep 20, 2014
@nikcorg
Copy link
Author

nikcorg commented Sep 20, 2014

Sorry for all the typos. This clearly isn't my best of days with regards to spelling.

browser.js Outdated
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather then special-casing ServiceWorkerGlobalScope, we should probably use global, global.document and global.navigator, which should work I would think.

What does global resolve to when you execute a browserified script as a ServiceWorker?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When in a browserify built bundle, it's an empty object. There is a global
'self' which resolves to 'global' which is a ServiceWorkerGlobalScope, but
that is just as bad or good. The spec is still unfinished, so the patch is
arguably questionable, but it shouldn't break anything in the form I've
submitted it.

.n
On 20 Sep 2014 19:46, "Nathan Rajlich" notifications@github.com wrote:

In browser.js:

@@ -35,12 +35,14 @@ exports.colors = [

function useColors() {
// is webkit? http://stackoverflow.com/a/16459606/376773

  • return ('WebkitAppearance' in document.documentElement.style) ||
  • return typeof ServiceWorkerGlobalScope == "undefined" && (

Rather then special-casing ServiceWorkerGlobalScope, we should probably
use global, global.document and global.navigator, which should work I
would think.

What does global resolve to when you execute a browserified script as a
ServiceWorker?


Reply to this email directly or view it on GitHub
https://github.com/visionmedia/debug/pull/139/files#r17820437.

When bundling `debug` using `browserify` the browser version is used, and the `useColors` check crashes when in a ServiceWorker, since `document`, `window` and `navigator` are all `undefined`.
Botched a parenthesis in the previous commit
@nikcorg nikcorg changed the title Adds check to useColors for ServiceWorker context Adds check to useColors for worker contexts Jan 21, 2015
@nikcorg
Copy link
Author

nikcorg commented Jan 21, 2015

@TooTallNate I modified the PR slightly. It now adds checks for WebWorker, SharedWorker and ServiceWorker contexts. They're still a bit special cased and possibly a bit unnecessarily explicit, but should do no harm.

@thebigredgeek
Copy link
Contributor

Closed in lieu of https://github.com/visionmedia/debug/pull/298/files

@thebigredgeek thebigredgeek added the feature This proposes or provides a feature or enhancement label Nov 14, 2016
@nikcorg nikcorg deleted the patch-1 branch November 14, 2016 18:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature This proposes or provides a feature or enhancement

Development

Successfully merging this pull request may close these issues.

3 participants