Closed Bug 1209445 Opened 9 years ago Closed 8 years ago

Missing ServiceWorker script gives confusing TypeError message - The expression cannot be converted to return the specified type

Categories

(Core :: DOM: Service Workers, defect)

44 Branch
defect
Not set
normal

Tracking

()

RESOLVED DUPLICATE of bug 1246615

People

(Reporter: duanyao.ustc, Unassigned)

References

(Blocks 1 open bug)

Details

(Whiteboard: [tw-dom] btpp-fixlater)

Attachments

(1 file)

User Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:44.0) Gecko/20100101 Firefox/44.0
Build ID: 20150928030206

Steps to reproduce:

Try some Service Worker demos, e.g.

  https://mdn.github.io/sw-test/

or

  http://jaoo.es/service-worker-testing/index.html

Pref dom.serviceWorkers.enabled is set true and Service Worker over HTTP is enabled.


Actual results:

Both demos fail because navigator.serviceWorker.register() generates TypeError - "The expression cannot be converted to return the specified type". I have no idea what this error means.


Expected results:

navigator.serviceWorker.register() should succeed.
Are you running these locally?

(In reply to Duan Yao from comment #0)
> Both demos fail because navigator.serviceWorker.register() generates
> TypeError - "The expression cannot be converted to return the specified
> type". I have no idea what this error means.

I get this message when I clone the mdn sw-test and run python -m SimpleHTTPServer in the same directory as the code.  The problem is that the registration uses an absolute path to service worker script as '/sw-test/sw.js'.  When the server is loading the files from the same directory, there is no sw-test path.

So this error seems related to not finding the sw.js script.

If I run python -m SimpleHTTPServer outside of sw-test so the paths all match, then the page loads correctly.

Both apps seem to work correctly online for me as well.

Lets use this bug to fix the error message.  We should try to do this for v1 if possible since its likely to be a common problem for developers.  We can bump back to v3 if its hard.
Status: UNCONFIRMED → NEW
Ever confirmed: true
Summary: Can't register Service Worker: navigator.serviceWorker.register() generates TypeError - The expression cannot be converted to return the specified type → Missing ServiceWorker script gives confusing TypeError message - The expression cannot be converted to return the specified type
Unfortunately I am still not able to get mdn sw-test working, even if I change it to use absolute URL:

  navigator.serviceWorker.register('http://localhost:8000/sw-test/sw.js', { scope: 'http://localhost:8000/sw-test/' })

same error.

I can confirm that http://localhost:8000/sw-test/sw.js is accessible if loaded from the address bar.

The online demos above do not work for me either.
You shouldn't need to change the register() call if you can load http://localhost:8000/sw-test/sw.js manually.  Does it work if you put those back?

Also, if you open the Browser Console by going to Menu -> Developer -> Browser Console, do you see any additional error messages there?

Have you locally modified the sw.js at all?
Just found that SW works fine if I use a new profile. Still no luck with my old profile, even if reset all service-worker-related prefs to default and disable all add-ons.

No additional error messages, just "Registration failed with TypeError: The expression cannot be converted to return the specified type."

I reverted all local changes to sw-test, no difference.
Please go to about:serviceworkers, click "update", then reload the page.  If that doesn't work, then try "unregister".
With my old profile, about:serviceworkers always says "No Service Workers registered".
With the new profile, "update" and "unregister" works as expected.

If this issue is hard to reproduce, maybe you can point out the code that generates this error, and I'll try to debug it myself.
You could do a DEBUG build and see if you're getting a NS_WARN_IF() or other failure in stderr output.
Bumping this down to v3, as we have a ton of similar issues with misleading error messages that we emit when you do something wrong.  We need to work on those for sure, but I don't think they should block us shipping the first release.
Blocks: ServiceWorkers-postv1
No longer blocks: ServiceWorkers-v1
Whiteboard: [tw-dom]
Assignee: nobody → jdai
John has several html bugs on his plate and plans to visit this afterwards, so "fixlater." John, feel free to correct if I misunderstood anything.
Whiteboard: [tw-dom] → [tw-dom] btpp-fixlater
Assignee: jdai → nobody
It's not clear there's anything actionable here that's not already covered by existing or fixed bugs:

Comment 1 (which was a guess by bkelly as to what the problem was in comment 0) has been fixed by bug 1267473 introducing improved error messages on network errors during registration.

Comment 4 and comment 6 suggest that the profile in question either:
- Was experiencing temporary "profile form the future" problems where some important subsystem like quota manager or DOM cache broke due to a database schema from a future version of firefox.  (Bug 1246615 generally covers this with dependencies covering specific instances.)
- Was experiencing quota manager breakage due to quota manager having trouble with an origin.  Certain cases (moz-safe-about:home) were improved in bug 1195930 and open, assigned bug 1286914 should improve things further.

Duan Yao, have you seen this bug recur?  If you still have the impacted profile around, it's possible that the Browser Console (control-shift-J) will include an error from the quota manager if things have not been fixed.
Flags: needinfo?(duanyao.ustc)
This issue still reproduce with 48.0 win32, however not reproduce with 50a2 win64. The error message of 48.0 when loading https://mdn.github.io/sw-test/ is "Registration failed with TypeError: ServiceWorker script at https://mdn.github.io/sw-test/sw.js for scope https://mdn.github.io/sw-test/ encountered an error during installation."

I attached a profile reproducing this issue, but I can't remember what action messed it up.
Flags: needinfo?(duanyao.ustc)
Yea, I just ran into this as well.  FF49 changed our QuotaManager disk format.  This profile is using the newer format and can't be opened in FF48 any more.  So its a dupe of bug 1246615.
Status: NEW → RESOLVED
Closed: 8 years ago
Resolution: --- → DUPLICATE
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: