setTimeout from content-script behaves crazy



5 years ago
5 years ago


(Reporter: gkrizsanits, Assigned: gkrizsanits)


Firefox Tracking Flags

(Not tracked)



(2 attachments)



5 years ago
It has all sort of issues like Bug 689615 or throwing exceptions like 
error: mozwebcompatreporter: An exception occurred.
[object Object]

or forgetting xray waivers... 

from IRC:

17:40 <hallvors> something like this...
<hallvors> var elm = foo.wrappedJSObject;
<hallvors> setTimeout(function(){'red' }, 100)
17:41 <hallvors> in normal JS, elm would be defined because the anonymous function has closure data
<hallvors> in the extension it seems elm is undefined when the timeout runs


5 years ago
Assignee: nobody → gkrizsanits
Created attachment 787615 [details]
mozwebcompatreporter.xpi - extension that shows the issue. Running it will open a tab and the relevant error appears in the console
My best guess (not being familiar with any of this) is that XRay wrappers may not be properly reference counted in content scripts, so that the XRay objects are garbage collected or deleted before the timeout occurs, even though they should be referenced from the timeout's closure data. (But another reasonable guess is that scopes get messed up, so that the timeout runs in a scope where these variables really don't exist..)

Either way, fixing this needs spec'ing how setTimeout in a content-script should behave. IMO the code should run in the content-script scope, having to use unsafeWindow and similar APIs for more direct access to the page's scope.

(If any of this didn't make sense or wasn't useful please ignore this newbie ;-))
Further debugging (thanks zombie_ on IRC) shows that setTimeout() is not the culprit and I was imagining problems because the code is running in an unexpected scope to begin with.
please re-open if you think this is still a problem
Last Resolved: 5 years ago
Resolution: --- → INVALID
There is one remaining problem here: the "[object Object]" error console output makes no sense and the exception was most unhelpful for any debugging. That's obviously not as high-pri as a messed up scope or closure problem in the engine, but gabor might want to keep this bug open to track it and fix it. I'll leave that to him.

Comment 6

5 years ago
(In reply to Hallvord R. M. Steen from comment #5)
> There is one remaining problem here: the "[object Object]" error console
> output makes

Do you know where is it coming from? It looks to me that someone is throwing an object with no toString on it (other than the one on Object.prototype). Is there a way to create a minimalistic reproducible test case for this?
No idea, but I'll see if I can reproduce in a minimal extension..
Created attachment 788197 [details]

basic extension - install it and load, check error console..
You need to log in before you can comment on or make changes to this bug.