Title: Proposed Bugfix: PWA Service Worker Having HTML Inserted Into JavaScript
Last modified: July 17, 2019

---

# Proposed Bugfix: PWA Service Worker Having HTML Inserted Into JavaScript

 *  Resolved [KZeni](https://wordpress.org/support/users/kzeni/)
 * (@kzeni)
 * [6 years, 10 months ago](https://wordpress.org/support/topic/plugin-conflict-pwa-service-worker-having-html-inserted-into-javascript/)
 * I’m currently using [https://wordpress.org/plugins/pwa/](https://wordpress.org/plugins/pwa/)
   on a site which then has `/?wp_service_worker=1` being called. This is expected
   to be a fully JavaScript-based response, but I’m seeing the HTML code for the
   HubSpot tracking being inserted at the top of this response.
 *     ```
       <!-- DO NOT COPY THIS SNIPPET! Start of Page Analytics Tracking for HubSpot WordPress plugin v7.5.5-->
       <script type="text/javascript">
       	var _hsq = _hsq || [];
       	_hsq.push(["setContentType", "standard-page"]);
       </script>
       <!-- DO NOT COPY THIS SNIPPET! End of Page Analytics Tracking for HubSpot WordPress plugin -->
       ```
   
 * Is exactly what’s found its way into my `/?wp_service_worker=1` response that
   should be JavaScript, and that’s obviously causing a syntax error.
 * I’d love to use these two plugins together, but it appears this plugin is breaking
   service workers so PWA is isn’t working fully as a result (which I need it to
   be).
 * I’ll reply with an update if I happen to find a solution to this problem.
 * **Update:** I’ve found a fix! See [https://wordpress.org/support/topic/plugin-conflict-pwa-service-worker-having-html-inserted-into-javascript/#post-11742072](https://wordpress.org/support/topic/plugin-conflict-pwa-service-worker-having-html-inserted-into-javascript/#post-11742072)
    -  This topic was modified 6 years, 10 months ago by [KZeni](https://wordpress.org/support/users/kzeni/).
      Reason: Updated to make note of the fact that I found a fix for the plugin
      issue

Viewing 6 replies - 1 through 6 (of 6 total)

 *  Thread Starter [KZeni](https://wordpress.org/support/users/kzeni/)
 * (@kzeni)
 * [6 years, 10 months ago](https://wordpress.org/support/topic/plugin-conflict-pwa-service-worker-having-html-inserted-into-javascript/#post-11742052)
 * Upon initial investigation, it seems like `/inc/class-leadin.php` has `add_leadin_frontend_scripts()`
   being called on `wp_enqueue_scripts` and `login_enqueue_scripts` which should
   be used for enqueuing CSS & JS when the `add_page_analytics()` function that’s
   called at the end of it actually just outputs HTML directly. It seems this is
   going against the expected WordPress conventions and breaking PWA (and possibly
   other plugins) as a result.
 * Really, `wp_footer` should be used instead of `wp_enqueue_scripts` and `login_footer`
   instead of `login_enqueue_scripts` since it’s outputting HTML that we want to
   be included before the page’s `</body>` tag.
 *  Thread Starter [KZeni](https://wordpress.org/support/users/kzeni/)
 * (@kzeni)
 * [6 years, 10 months ago](https://wordpress.org/support/topic/plugin-conflict-pwa-service-worker-having-html-inserted-into-javascript/#post-11742072)
 * In summary, it appears `/inc/class-leadin.php` needs
 *     ```
       // Adds the leadin-tracking script to wp-login.php page which doesnt hook into the enqueue logic.
       if ( $this->leadin_is_login_or_register_page() ) {
       	add_action( 'login_enqueue_scripts', array( $this, 'add_leadin_frontend_scripts' ) );
       } else {
       	add_action( 'wp_enqueue_scripts', array( $this, 'add_leadin_frontend_scripts' ) );
       }
       ```
   
 * to be changed to
 *     ```
       if ( $this->leadin_is_login_or_register_page() ) {
       	add_action( 'login_footer', array( $this, 'add_leadin_frontend_scripts' ) );
       } else {
       	add_action( 'wp_footer', array( $this, 'add_leadin_frontend_scripts' ) );
       }
       ```
   
 * to behave how WordPress expects.
 * This keeps the plugin’s existing functionality while preventing a conflict with
   PWA & potentially other plugins.
 * I would love to see this fix implemented in a future update of this plugin.
 *  Thread Starter [KZeni](https://wordpress.org/support/users/kzeni/)
 * (@kzeni)
 * [6 years, 10 months ago](https://wordpress.org/support/topic/plugin-conflict-pwa-service-worker-having-html-inserted-into-javascript/#post-11745443)
 * As an aside, I’ve cross-posted this on the HubSpot Community forum at [https://community.hubspot.com/t5/Marketing-Integrations/Proposed-Bugfix-for-WordPress-Plugin-PWA-Service-Worker-Having/m-p/281254/highlight/true#M1633](https://community.hubspot.com/t5/Marketing-Integrations/Proposed-Bugfix-for-WordPress-Plugin-PWA-Service-Worker-Having/m-p/281254/highlight/true#M1633)
   since I wanted to share/discuss this wherever people might be looking.
 * Again, hopefully this fix can be officially adopted in a version update.
 *  [David Ly Khim](https://wordpress.org/support/users/davidlykhim/)
 * (@davidlykhim)
 * [6 years, 10 months ago](https://wordpress.org/support/topic/plugin-conflict-pwa-service-worker-having-html-inserted-into-javascript/#post-11745517)
 * Hi [@kzeni](https://wordpress.org/support/users/kzeni/) thanks for flagging this.
   We’ve tested that in our environment and will release a fix in the next update!
 *  Thread Starter [KZeni](https://wordpress.org/support/users/kzeni/)
 * (@kzeni)
 * [6 years, 10 months ago](https://wordpress.org/support/topic/plugin-conflict-pwa-service-worker-having-html-inserted-into-javascript/#post-11745521)
 * Thanks for the update, [@davidlykhim](https://wordpress.org/support/users/davidlykhim/)!
   I look forward to the new release 🙂
 *  Thread Starter [KZeni](https://wordpress.org/support/users/kzeni/)
 * (@kzeni)
 * [6 years, 10 months ago](https://wordpress.org/support/topic/plugin-conflict-pwa-service-worker-having-html-inserted-into-javascript/#post-11748810)
 * Okay, it looks like 7.6.0 has resolved this issue.
 * Thanks!

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Proposed Bugfix: PWA Service Worker Having HTML Inserted Into JavaScript’
is closed to new replies.

 * ![](https://ps.w.org/leadin/assets/icon-256x256.png?rev=3041936)
 * [HubSpot All-In-One Marketing - Forms, Popups, Live Chat](https://wordpress.org/plugins/leadin/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/leadin/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/leadin/)
 * [Active Topics](https://wordpress.org/support/plugin/leadin/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/leadin/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/leadin/reviews/)

 * 6 replies
 * 2 participants
 * Last reply from: [KZeni](https://wordpress.org/support/users/kzeni/)
 * Last activity: [6 years, 10 months ago](https://wordpress.org/support/topic/plugin-conflict-pwa-service-worker-having-html-inserted-into-javascript/#post-11748810)
 * Status: resolved