The Solution of Script Error Problem



When third-party scripts report errors, they do not expose detailed error information because of cross-domain problems. Instead, they are uniform.Script error

The Solution of Script Error Problem

What we have come across ispageandjsThe secondary domain name is the same, and it is set up.document.domainChrome browsers can display detailed error stacks; however, many mobile browsers still doScript error


The CDN we use is Ali Yun. In fact, he has given the solution to this problem.

After reading, we know that just add the crossorigin attribute to the script tag, and the effect is as follows

The Solution of Script Error Problem

Specific methods

Our project useswebpackPlug-ins that modify HTML should be used by everyonehtml-webpack-pluginThe derivative plug-in of this plug-inscript-ext-html-webpack-pluginTo meet our needs.

plugins: [
  new HtmlWebpackPlugin({
    inject: true,
    template: paths.appHtmlProd,
  new ScriptExtHtmlWebpackPlugin({
    custom: {
      test: /\.js$/,
      attribute: 'crossorigin',
      value: 'anonymous'