Skip to content
This repository has been archived by the owner on Feb 3, 2022. It is now read-only.

Not returning serviceworker.js #18

Open
bloggerpact opened this issue Oct 17, 2017 · 14 comments
Open

Not returning serviceworker.js #18

bloggerpact opened this issue Oct 17, 2017 · 14 comments

Comments

@bloggerpact
Copy link

bloggerpact commented Oct 17, 2017

Hey @tgerulaitis

I used the modman to install the plugin, everything looks okay from the back-end have https enabled cleared cache but the url.com/serviceworker.js service worker does not return Javascript. I'm using custom theme & also tried with rwd theme.
In waiting for your quick response

@tgerulaitis
Copy link
Member

Hi @bloggerpact,

What version of Magento are you running? Do you have "Allow Symlinks" set to "Yes" in System > Configuration > Advanced > Developer > Template Settings (You might not have that setting anymore if you're running on the latest version of Magento)?

First thing I would try is running:

modman deploy --copy magento-meanbee-pwa

Then flushing the Magento cache and running through setup scripts.

@fintzen
Copy link

fintzen commented Jan 8, 2018

I cleared cache and become this error message.
console.log('Service worker registration failed:', err);
url.com/serviceworker.js is just a blank page - not code.

In Safari = Blank page
In Firefox = Blank page
In Chrome = /serviceworker.js Failed to load resource: net::ERR_INVALID_RESPONSE
(index):95 Service worker registration failed: TypeError: Failed to register a ServiceWorker: A bad HTTP response code (500) was received when fetching the script.

I use magento 1.9.1.1 and i have "Allow symlinks" enabled.
What do I'm wrong?

@tgerulaitis
Copy link
Member

@fintzen, looks like there's an exception being thrown on the server, resulting in a 500 HTTP response code. Could you check var/log/exception.log and var/log/system.log for any relevant error messages?

@fintzen
Copy link

fintzen commented Jan 9, 2018

@tgerulaitis i found this 3 errors in system.log

2018-01-09T09:36:01+00:00 ERR (3): Warning: simplexml_load_string(): Entity: line 55: parser error : Start tag expected, '<' not found in /html/magento/app/code/core/Mage/Core/Model/Layout/Update.php on line 450
2018-01-09T09:36:01+00:00 ERR (3): Warning: simplexml_load_string(): in /html/magento/app/code/core/Mage/Core/Model/Layout/Update.php on line 450
2018-01-09T09:36:01+00:00 ERR (3): Warning: simplexml_load_string(): ^ in /html/magento/app/code/core/Mage/Core/Model/Layout/Update.php on line 450

@tgerulaitis
Copy link
Member

@fintzen , that's strange. The error messages seem to indicate that you have an invalid layout xml file. I would check app/design/frontend/base/default/layout and app/design/frontend/<yourpackage>/<yourtheme>/layout for any xml files that have invalid code at the start. Although, I'm not sure if this is going to be related to your problems generating the service worker file.

Just to eliminate another common issue, what web server are you using for Magento? Apache or Nginx? If it's Nginx, does it allow /serviceworker.js to be served by PHP? (I've seen a lot of Nginx configurations that assume anything ending in .js is a file and not letting PHP respond)

@fintzen
Copy link

fintzen commented Jan 9, 2018

@tgerulaitis , now i found the invalid code at the start of a page.xml file.
But it was not the problem that was related to the service worker problem.

I use a apache server for magento.
I really have no idea why the service worker is not working.

@tgerulaitis
Copy link
Member

@fintzen, Yeah, I'm not sure either, unfortunately. I've set up a fresh instance of Magento 1.9.1.1 myself locally to test this and I'm not seeing any errors running the module. Unfortunately, without more information about the problem there's nothing else I can do.

Have you looked at your web server error logs or PHP logs?

@fintzen
Copy link

fintzen commented Jan 14, 2018

I can't find any other error logs on my server.
Now I have a little bit trying to start the ServiceWorker.
I put the .js on direct in the directory url.com/serviceworker.js
Now I have a other error message.
serviceworker_request_failed

@tgerulaitis
Copy link
Member

@fintzen the serviceworker.js file in the templates directory is not a valid service worker file. It's a template that contains PHP tags which Magento should evaluate and replace with appropriate values. It's not going to work if being served directly through the web server.

@fintzen
Copy link

fintzen commented Jan 15, 2018

@tgerulaitis, oh yes I'm really sorry for that dumb comment. 😅
I just see my server can't find the resource - so I put it in there to test if it's run.
bildschirmfoto 2018-01-15 um 11 46 56

@rafaelpatro
Copy link

Same problem with me!
Load layout was not loading properly. It was rendering a blank page too.
This was because another extension or theme was applying a block without a referencing block (without ancestor, without parent). Only root block could do it.

It was solved by locating the extension and updating meanbee_pwa.xml.
Added a new removal tag: <remove name="sucking-extension-block" />

Good luck!

@fintzen
Copy link

fintzen commented Feb 2, 2018

@rafaelpatro, Wich extension / wich block was the problem? Maybe we use the same.

@rafaelpatro
Copy link

Extension: Mirasvit Searchautocomplete
File: /app/design/frontend/base/default/layout/mst_searchautocomplete.xml

<?xml version="1.0"?>
<layout version="0.1.0">
    <default>
        <reference name="head">
            <action method="addJs" ifconfig="searchautocomplete/general/enabled"><script>mirasvit/core/jquery.min.js</script></action>
            <action method="addJs" ifconfig="searchautocomplete/general/enabled"><script>mirasvit/core/underscore.js</script></action>
            <action method="addJs" ifconfig="searchautocomplete/general/enabled"><script>mirasvit/core/backbone.js</script></action>
            <action method="addJs" ifconfig="searchautocomplete/general/enabled"><script>mirasvit/code/searchautocomplete/form.js</script></action>
            <action method="addJs" ifconfig="searchautocomplete/general/enabled"><script>mirasvit/code/searchautocomplete/autocomplete.js</script></action>
            <action method="addItem" ifconfig="sales/msrp/enabled"><type>skin_js</type><name>js/msrp.js</name></action>
        </reference>

        <block type="searchautocomplete/layout" name="search.block">
            <action method="addSearchAutocomplete" ifconfig="searchautocomplete/general/enabled" />
        </block>

Solution

Edit: /app/design/frontend/base/default/layout/meanbee_pwa.xml
Add a removal tag for search.block:

<?xml version="1.0"?>
<layout>
    <default>
        <reference name="after_body_start">
            <block name="serviceworker.register" type="meanbee_pwa/serviceworker_register" template="pwa/serviceworker/register.phtml"/>
        </reference>
    </default>

    <serviceworker_index_js>
        <remove name="root"/>
        <remove name="search.block"/>
        <block name="serviceworker.js" type="meanbee_pwa/serviceworker_js" template="pwa/serviceworker/serviceworker.js" output="toHtml"/>
    </serviceworker_index_js>
</layout>

@tgerulaitis
Copy link
Member

Excellent, thank you @rafaelpatro !

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants