webtor-io/embed-sdk-js

Unable to import as module

edwinork opened this issue · 3 comments

I noticed that the only way to use this package is by directly downloading it from CDN in a script tag, like so:
<script src="https://cdn.jsdelivr.net/npm/@webtor/embed-sdk-js/dist/index.min.js" charset="utf-8" async></script>

I can install it via package manager and import with either require("@webtor/embed-sdk-js/dist/index.min.js") or import "@webtor/embed-sdk-js/dist/index.min.js. The script loads into the browser correctly. However, when I use webtor.push, the Webtor embed doesn't show up.

I did some debugging and found that the problem happens here:

else if (d.name == self.INJECT) {
            eval(d.data);
}

d.data contains a code snippet that looks for the exact CDN link in script tags, like so:
scripts[i].src.includes('https://cdn.jsdelivr.net/npm/@webtor/')
If the CDN link is not found, then the check fails and Webtor embed never gets loaded. When I remove the CDN link check from d.data, Webtor embed works as expected even if imported as module.

Here are some pros for being able to import as module:

  • straight forward versioning via package manager
  • easier to use with UI frameworks (ex. Removes the need to manually create script tags in the DOM inside a React component)
  • more control with bundlers (ex. Dynamic imports with code splitting)
  • reference to corresponding type definitions

It is quite a long story. My service is supported by ads and donations, because I have to cover server costs. As you can see from the code, ads are injected from embed to parent window. At some point one site owner decided to prevent ads from showing at his site, so he changed the source code of embed-sdk-js to do this. Checking of specific script presence was added just to prevent such activity and to ensure that only original code was loaded. I really understand the use of modules and packages, webtor.io UI heavily relies on them, but I can't figure out how I will control that code of embed-sdk-js is original in this case. @edwinork do you have any ideas?

Hey @vintikzzz! I wrote you an email regarding this to pavel.tatarsky@gmail.com

stale commented

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.