Support » Plugin: HubSpot - CRM, Email Marketing, Live Chat, Forms & Analytics » Proposed Bugfix: PWA Service Worker Having HTML Inserted Into JavaScript

  • Resolved KZeni

    (@kzeni)


    I’m currently using 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

    • This topic was modified 10 months, 3 weeks ago by 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)
  • 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.

    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.

    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 since I wanted to share/discuss this wherever people might be looking.

    Again, hopefully this fix can be officially adopted in a version update.

    Plugin Support David Ly Khim

    (@davidlykhim)

    Hi @kzeni thanks for flagging this. We’ve tested that in our environment and will release a fix in the next update!

    Thanks for the update, @davidlykhim! I look forward to the new release 🙂

    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.