Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Firefox: ReferenceError: document is not defined #141

Closed
adam-p opened this issue Nov 6, 2013 · 20 comments

Comments

Projects
None yet
6 participants
@adam-p
Copy link
Owner

commented Nov 6, 2013

Reported here: https://groups.google.com/forum/#!topic/markdown-here/ikXFqkP77Ws


MDH has been working great for me until somewhat recently (a week or two?). I've noticed that there are occasions when I can't toggle the text of my reply.

I'm on Firefox, used on both Windows and Ubuntu. I open up the Browser Console and watch when I make a failed attempt to toggle. The error I get is:

ReferenceError: document is not defined                                options-store.js:336

That code does seem to line up with line 336 of HEAD, implying that I'm on the latest version.

Any ideas for a fix?

@adam-p

This comment has been minimized.

Copy link
Owner Author

commented Nov 6, 2013

My reply:


Interesting. That code is only supposed to be hit (iirc) when the rendering is being done from the options page — not under normal email circumstances.

What version of Firefox are you using? And what sites (email clients) is it failing for (besides GGroups, I guess)?

I can’t seem to reproduce the problem, so…

I added some additional exception logging, and made a change that might fix the problem. See changes here: 1ff7315. At the very least, we’ll be able to see exactly what exception is being thrown (maybe it’s a JSON exception or something).

That change will be in the next release — this weekend at the latest. (Of course, Mozilla approval takes a while after that.) I’ll reply to this message after I release, and then please let me/us know if it’s still busted after you get the update.

Thanks.

Adam

@stoicflame

This comment has been minimized.

Copy link

commented Nov 6, 2013

What version of Firefox are you using?

I'm using FF 25.0 on both Windows and Ubuntu. It happens on both platforms.

And what sites (email clients) is it failing for (besides GGroups, I guess)?

GMail, Outlook Web Access, Evernote.

I can’t seem to reproduce the problem

Huh. I wonder if it's some strange brew of my add-ons and other configuration. FWIW, I'll dump by about:support data at the end of this comment here.

I added some additional exception logging, and made a change that might fix the problem.

Awesome. Thanks. I'll report back when I get the update.

about:support

Application Basics
------------------

Name: Firefox
Version: 25.0
User Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:25.0) Gecko/20100101 Firefox/25.0

Extensions
----------

Name: Adblock Plus
Version: 2.4
Enabled: true
ID: {d10d0bf8-f5b5-c8b4-a8b2-2b9879e08c5d}

Name: Copy Plain Text 2
Version: 1.2.1
Enabled: true
ID: copyplaintext@teo.pl

Name: feedly
Version: 16.0.528
Enabled: true
ID: feedly@devhd

Name: Firebug
Version: 1.12.4
Enabled: true
ID: firebug@software.joehewitt.com

Name: FireGestures
Version: 1.7.14
Enabled: true
ID: firegestures@xuldev.org

Name: JSONView
Version: 0.7
Enabled: true
ID: jsonview@brh.numbera.com

Name: Live HTTP headers
Version: 0.17
Enabled: true
ID: {8f8fe09b-0bd3-4470-bc1b-8cad42b8203a}

Name: Markdown Here
Version: 2.9.3
Enabled: true
ID: markdown-here@adam.pritchard

Name: Poster
Version: 3.1.0
Enabled: true
ID: {d48a39ba-8f80-4fce-8ee1-bc710561c55d}

Name: Ubuntu Firefox Modifications
Version: 2.7
Enabled: true
ID: ubufox@ubuntu.com

Name: Web Developer
Version: 1.2.5
Enabled: true
ID: {c45c406e-ab73-11d8-be73-000a95be3b12}

Important Modified Preferences
------------------------------

accessibility.typeaheadfind.flashBar: 0
browser.cache.disk.capacity: 1048576
browser.cache.disk.enable: false
browser.cache.disk.smart_size_cached_value: 1048576
browser.cache.disk.smart_size.first_run: false
browser.cache.memory.capacity: 262144
browser.history_expire_days.mirror: 180
browser.places.createdSmartBookmarks: true
browser.places.importBookmarksHTML: false
browser.places.importDefaults: false
browser.places.leftPaneFolderId: -1
browser.places.migratePostDataAnnotations: false
browser.places.smartBookmarksVersion: 4
browser.places.updateRecentTagsUri: false
browser.sessionstore.upgradeBackup.latestBuildID: 20131028113308
browser.startup.homepage: http://mail.google.com/mail/
browser.startup.homepage_override.buildID: 20131028113308
browser.startup.homepage_override.mstone: 25.0
browser.tabs.loadInBackground: false
browser.tabs.onTop: false
dom.max_script_run_time: 0
dom.mozApps.used: true
dom.w3c_touch_events.expose: false
extensions.lastAppVersion: 25.0
font.minimum-size.x-western: 10
gfx.blacklist.suggested-driver-version: <Anything with EXT_texture_from_pixmap support>
network.cookie.prefsMigrated: true
network.protocol-handler.app.sshto: /home/heatonra/bin/ssh-terminal.sh
network.protocol-handler.external.sshto: true
places.database.lastMaintenance: 1383670974
places.history.expiration.transient_current_max_pages: 104858
places.history.expiration.transient_optimal_database_size: 167772160
places.last_vacuum: 1304097639
plugin.disable_full_page_plugin_for_types: application/pdf
plugin.importedState: true

... a bunch of print.* preferences ...

privacy.popups.showBrowserMessage: false
privacy.sanitize.migrateFx3Prefs: true
storage.vacuum.last.index: 1
storage.vacuum.last.places.sqlite: 1383584307

Graphics
--------

Adapter Description: NVIDIA Corporation -- Quadro 1000M/PCIe/SSE2
Device ID: Quadro 1000M/PCIe/SSE2
Driver Version: 4.2.0 NVIDIA 304.88
GPU Accelerated Windows: 0/1 Basic
Vendor ID: NVIDIA Corporation
WebGL Renderer: NVIDIA Corporation -- Quadro 1000M/PCIe/SSE2
windowLayerManagerRemote: false
AzureCanvasBackend: cairo
AzureContentBackend: none
AzureFallbackCanvasBackend: none
AzureSkiaAccelerated: 0

JavaScript
----------

Incremental GC: true

Accessibility
-------------

Activated: false
Prevent Accessibility: 0

Library Versions
----------------

NSPR
Expected minimum version: 4.10.1
Version in use: 4.10.1

NSS
Expected minimum version: 3.15.2 Basic ECC
Version in use: 3.15.2 Basic ECC

NSSSMIME
Expected minimum version: 3.15.2 Basic ECC
Version in use: 3.15.2 Basic ECC

NSSSSL
Expected minimum version: 3.15.2 Basic ECC
Version in use: 3.15.2 Basic ECC

NSSUTIL
Expected minimum version: 3.15.2
Version in use: 3.15.2
@adam-p

This comment has been minimized.

Copy link
Owner Author

commented Nov 8, 2013

I got this error as well now. Here's the console output:

[13:29:46.827] Markdown Here: failing back to content script preferences code
[13:29:46.827] [Exception... "Component returned failure code: 0xc1f30001 (NS_ERROR_NOT_INITIALIZED) [nsIDOMJSWindow.setTimeout]"  nsresult: "0xc1f30001 (NS_ERROR_NOT_INITIALIZED)"  location: "JS frame :: resource://markdown_here_common/utils.js :: nextTick :: line 469"  data: no]
[13:29:46.827] ReferenceError: document is not defined @ resource://markdown_here_common/options-store.js:339

I haven't had time to look into it further.

@stoicflame

This comment has been minimized.

Copy link

commented Nov 11, 2013

I can confirm the issue still occurs for me. It looks exactly as reported by @adam-p at above comment.

@stoicflame

This comment has been minimized.

Copy link

commented Feb 22, 2014

Bump.

Any progress to report on this issue?

@adam-p

This comment has been minimized.

Copy link
Owner Author

commented Feb 23, 2014

Maybe? I'm glad you reminded me...

I asked on the Mozilla dev forum and I was told to test with a clean profile. So I created a pristine profile, ran Firefox (Aurora) for a whole week with Gmail open, and... no error.

(I'm worried that the fact that I wasn't actively using that browser/Gmail during the week may have tainted the test, but let's ignore that for now.)

So the problem is actually one of the other extensions I have installed...? And you? And @darickard?

Here are the other extensions I have:

  • Adblock Plus
  • LastPass
  • NoScript
  • Pocket
  • Tab Mix Plus
  • Tree Style Tab
  • some disabled development extensions

What extensions do you guys have?

I guess the next thing I should do is add all of my extensions to my pristine profile and reproduce the problem.


Edited to add: I just realized @stoicflame included his extensions above. We have Adblock Plus in common (and some of the dev extensions that I keep disabled until I need them).

@stoicflame

This comment has been minimized.

Copy link

commented Feb 24, 2014

Here's my list:

  • Adblock Plus
  • Copy Plain Text 2
  • feedly
  • Firebug
  • FireGestures
  • JSONView
  • Live HTTP Headers
  • Markdown Here
  • Poster
  • Web Developer

The only add-on I see that we have in common is Adblock Plus. Although it would be sad for me to have to choose between MDH and Adblock...

@darickard

This comment has been minimized.

Copy link

commented Feb 24, 2014

Thanks for continuing to look into this. Here are mine - all are enabled:
Adblock Plus
Aero Window Title
ColorZilla
Cookies Manager+
DNS Flusher
DOM Inspector
Firebug
Forecastfox
FoxyProxy Standard
Gmelius
Greasemonkey
HttpFox
LastPass
Markdown Here
Open With
Poster
Restart Button
RESTClient
Server Spy
ShowIP
Stylish
Tab Mix Plus
Table2Clipboard
Uppity
View Source Chart
ViewSourceWith
Web Developer
Xmarks

@adam-p

This comment has been minimized.

Copy link
Owner Author

commented Feb 28, 2014

I added Adblock Plus (2.5.1) to my pristine profile, opened Gmail, and left Firefox (27.0.1) open for 3 days. No result. Rendering still works fine. And now I need to shut my computer down.

Maybe three days isn't long enough? Maybe letting the browser sit idle isn't a good test? When I'm able to try this again I'll make that browser instance my primary-use profile (which is going to drive me insane -- I won't have any of my other usual extensions...).

@darickard

This comment has been minimized.

Copy link

commented Feb 28, 2014

Thanks again for staying on this and sorry about the drive to insanity. I know exactly what you mean about not having your usual extensions. The things that make Firefox great - the extensibility, customizability, etc. - make it difficult to troubleshoot.

@adam-p

This comment has been minimized.

Copy link
Owner Author

commented Mar 1, 2014

We will conquer this demon! ...Just not while I'm away for a week at a conference.

@adam-p

This comment has been minimized.

Copy link
Owner Author

commented Mar 9, 2014

Another data point: I just this behaviour in a Gmail tab that I had just opened. The browser has been open for two days (on a laptop -- lid closed on and off), but I hadn't opened Gmail in it until just now.

This isn't a revelation, but I hadn't seen it before.

This issue is quickly becoming a critical pain in my ass.

@JacobEvelyn

This comment has been minimized.

Copy link

commented Jun 3, 2014

I'm seeing the same behavior, and have been seeing it for a few months at least. It seems to happen when my browser's been open for awhile but I haven't tested it thoroughly enough to know if (a) that's what's actually causing trouble, and (b) how long "awhile" is.

The error in the browser console:

Markdown Here: failing back to content script preferences code
[Exception... "Component not initialized"  nsresult: "0xc1f30001 (NS_ERROR_NOT_INITIALIZED)"  location: "JS frame :: resource://markdown_here_common/utils.js :: nextTick :: line 596"  data: no]
ReferenceError: document is not defined              options-store.js:343

If it's helpful, my addons are:

  • Boomerang for GMail
  • Close Tabs to the Right
  • Dashlane
  • Dictionary Extension
  • Markdown Here (whooo!)
  • Meldium
  • Omnibar
  • Prevent Tab Overflow
  • Privacy Badger Firefox
  • Rapportive
  • Tab for a Cause

@adam-p adam-p added the high label Aug 26, 2014

@adam-p

This comment has been minimized.

Copy link
Owner Author

commented Sep 7, 2014

Thanks to @iagobozza in #189 I finally have a solid reproduction scenario:

  1. Open Firefox. Go to MDH options page (or Gmail compose or whatever). Do some toggling to see it works.
  2. Open a new Firefox window (ctrl+n).
  3. Switch back to first Firefox window. Do some more toggling to see that it still works.
  4. Close the newer window.
  5. In the first Firefox window, try to toggle. It's broken.

It's just that easy. When you open and close a new window, it gets broken. When you open another new window, it starts working again (even in the first window).

My gut feeling is that this is related to the Utils.global hackery. I'll do some looking later today to see if I can nail it down (and fix it).

@adam-p

This comment has been minimized.

Copy link
Owner Author

commented Sep 11, 2014

Fixed in rev ad6bcc3. Phew! This will be in the next release (which will be this weekend at the latest).

The problem, in brief: There are two (ish) ways of loading code modules in Firefox/Gecko: mozIJSSubScriptLoader and Components.utils.import. It seems/seemed like Cu.import is more efficient, so I tried to use that more. But it has a drawback: it doesn't have access to the DOM or window object. That means it's a pain to call setTimeout or do XHR stuff, etc.

I hacked around that by storing a reference to background chrome window. It got set every time a new window opened. But... if the last window that got opened then got closed... the reference to it was invalid and our bug happened.

I "fixed" it by going back to using mozIJSSubScriptLoader. The documentation suggests that there's not actually a performance problem, and it behaves more like Chrome and Safari. So I guess that's good.

Dirty hacks cause bugs, you guys!

@adam-p adam-p closed this Sep 11, 2014

@darickard

This comment has been minimized.

Copy link

commented Sep 11, 2014

Thank you for sticking with this one, Adam. Keep up the good work!

@stoicflame

This comment has been minimized.

Copy link

commented Sep 11, 2014

w00t!

@seanfisk

This comment has been minimized.

Copy link

commented Sep 11, 2014

Thanks for fixing this, awesome!

@JacobEvelyn

This comment has been minimized.

Copy link

commented Sep 11, 2014

Great work! Thank you!

@caseywatts

This comment has been minimized.

Copy link

commented Sep 18, 2014

woo! :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.