Skip to content
This repository has been archived by the owner on Dec 29, 2022. It is now read-only.

Split the data URI only once. #40

Merged
merged 1 commit into from Aug 5, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions extension/background.js
Expand Up @@ -37,18 +37,19 @@ const API_URL = goog.define('API_URL', 'https://test-safebrowsing.google.com');
* @return {!Uint8Array} A Uin8Array representation of the image.
*/
const getIntArrayFromDataUrl = dataUrl => {
const urlParts = dataUrl.split(',');
// Separate out the mime component, which comes after the data: prefix and
// before ;base64. e.g., image/png for screenshot data.
const mimeString =
dataUrl.split(',')[0].split(':')[1].split(';')[0];
urlParts[0].split(':')[1].split(';')[0];
// Since the data URL is retrieved from chrome.tabs.captureVisibleTab with
// the format set to png, verify that the mimeString matches.
if (mimeString !== 'image/png') {
throw Error('Screenshot is in incorrect format');
}
// Convert base 64 to raw binary data held in a string. The data segment
// comes after the comma in a data URL.
const byteString = atob(dataUrl.split(',')[1]);
const byteString = atob(urlParts[1]);
// Write the bytes of the string to an ArrayBuffer.
const intArray =
new Uint8Array(new ArrayBuffer(byteString.length));
Expand Down