silentbox icon indicating copy to clipboard operation
silentbox copied to clipboard

btoa is not defined

Open jewe11er opened this issue 5 years ago • 5 comments
trafficstars

Get error "btoa is not defined" Line 293 in vue-silentbox.umd.js

jewe11er avatar Mar 20 '20 20:03 jewe11er

Could you please describe the error a little bit more?

silencesys avatar Mar 22 '20 17:03 silencesys

I tried to use Silentbox in Nuxt app.

jewe11er avatar Mar 22 '20 19:03 jewe11er

I had the same problem in gridsome!

I fixed it by rendering the gallery only on the client side. In my case the code looks something like this:

    <ClientOnly>
      <silent-box  :gallery="gallery" ></silent-box>
    </ClientOnly>

Don't ask me why, but apparently you can't server-side render the plugin!

ArmanNik avatar Jun 26 '20 15:06 ArmanNik

Thank you for reporting, I'll check that out. I use window and document objects in Silentbox, so it might be due to that.

silencesys avatar Jul 08 '20 09:07 silencesys

It's caused by this part:

if (css.map) {
  // https://developer.chrome.com/devtools/docs/javascript-debugging
  // this makes source maps inside style tags work properly in Chrome
  code += '\n/*# sourceURL=' + css.map.sources[0] + ' */'; // http://stackoverflow.com/a/26603875

  code += '\n/*# sourceMappingURL=data:application/json;base64,' + btoa(unescape(encodeURIComponent(JSON.stringify(css.map)))) + ' */';
}

client-side only fixes it :+1:

tennox avatar Jan 15 '21 00:01 tennox