Answer the question
In order to leave comments, you need to log in
How to get Data URL synchronously?
Using XMLHttpRequest I can synchronously download the file I need.
How would I then also synchronously convert the downloaded to Data URL ?
This is for a browser extension. The chrome.webRequest.onBeforeRequest event requires a synchronous callback as its first parameter. Allows you to edit the scripts of the target site. That is, inside this event, I can synchronously download the current script, make edits, and then send it back as a redirect to Data URL .
Answer the question
In order to leave comments, you need to log in
Download the file as an ArrayBuffer, then encode it as base64
, for example, this
btoa is a little crazy - be sure to give it an array of bytes as a string, that is, for example, a binary array [208, 144, 208, 145], which symbolizes the string "AB" in the encoding utf8 must be converted to a string of 4 characters String.fromCharCode(208, 144, 208, 145). But in principle it is also possible.
Well, btoa is not suitable for the downloaded string, because the text there is already in utf16
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question