Chrome Extension Integration with HubSpot Tracking - Protocol Issues

I’m trying to implement HubSpot analytics tracking inside my Chrome extension but running into issues with URL protocols. The main problem is that Chrome extensions use the chrome:// protocol instead of standard http/https protocols.

What I’ve tried:

  • Modified the script source to use HTTPS protocol directly
  • Added the required domain permissions in my manifest file

The Problem:
When the HubSpot script executes, it attempts to load additional resources using relative URLs. These get converted to chrome://track.hubspot.com which obviously fails to load.

My Question:
Is there a way to fix this protocol issue without downloading and manually editing the HubSpot tracking script? I’m looking for a cleaner solution that doesn’t require maintaining a modified version of their code.

Any suggestions or workarounds would be really helpful. Thanks!

had similar headache with mixpanel tracking. try injecting the hubspot script into actual webpage context instead of extension context - use content script to insert script tag directly into page DOM. this way it runs under normal http protocol and avoids the chrome:// mess entirely.

Another approach that’s worked well for me is using the webRequest API to intercept and redirect those problematic chrome:// URLs back to their proper HTTPS equivalents. You’ll need to add webRequest permissions to your manifest and set up listeners that catch any requests starting with chrome://track.hubspot.com and redirect them to https://track.hubspot.com instead. This keeps the original HubSpot script intact while solving the protocol mismatch at the network level. The key is implementing this before the HubSpot script loads so the redirects are already in place when it tries to fetch additional resources. I’ve used this method with several analytics platforms and it tends to be more maintainable than modifying third-party scripts directly.

Had this exact same issue when building an extension that needed to track user interactions through Google Analytics. The chrome:// protocol conflict is a common pain point that most developers hit. What worked for me was setting up a background script that acts as a proxy between your extension and HubSpot’s servers. Instead of loading HubSpot directly, create API endpoints in your background script that can make proper HTTPS requests to HubSpot’s tracking endpoints. This approach gives you full control over the data being sent and eliminates the protocol mismatch entirely. You can structure the tracking data according to HubSpot’s API documentation and send it through XMLHttpRequest or fetch from the background context. The downside is you lose some of the automatic features that their standard script provides, but you gain much better control and reliability.