From 70fd0f02dd40b384344b2a696e674b9e31cdc591 Mon Sep 17 00:00:00 2001 From: Gerben Date: Thu, 13 Jul 2017 23:20:39 +0200 Subject: [PATCH 1/4] Spin off src/util/when-all-settled. https://www.npmjs.com/package/when-all-settled --- package.json | 3 ++- src/freeze-dry/common.js | 2 +- src/freeze-dry/index.js | 2 +- src/freeze-dry/inline-images.js | 2 +- src/freeze-dry/inline-styles.js | 2 +- src/page-analysis/background/index.js | 2 +- src/util/when-all-settled.js | 32 --------------------------- yarn.lock | 6 +++++ 8 files changed, 13 insertions(+), 38 deletions(-) delete mode 100644 src/util/when-all-settled.js diff --git a/package.json b/package.json index 2ae261839..c5dc9c0b7 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,8 @@ "semantic-ui-css": "git+https://github.com/Treora/semantic-ui-css.git#1d2237f", "semantic-ui-react": "^0.70.0", "tldjs": "^1.7.0", - "webextension-polyfill": "^0.1.1" + "webextension-polyfill": "^0.1.1", + "when-all-settled": "^0.1.1" }, "devDependencies": { "autoprefixer": "^7.1.1", diff --git a/src/freeze-dry/common.js b/src/freeze-dry/common.js index 803eeb165..f73cd3669 100644 --- a/src/freeze-dry/common.js +++ b/src/freeze-dry/common.js @@ -1,5 +1,5 @@ import responseToDataUri from 'src/util/response-to-data-uri' -import whenAllSettled from 'src/util/when-all-settled' +import whenAllSettled from 'when-all-settled' export function removeNode(node) { diff --git a/src/freeze-dry/index.js b/src/freeze-dry/index.js index 9f40c62f1..79b648cec 100644 --- a/src/freeze-dry/index.js +++ b/src/freeze-dry/index.js @@ -1,4 +1,4 @@ -import whenAllSettled from 'src/util/when-all-settled' +import whenAllSettled from 'when-all-settled' import inlineStyles from './inline-styles' import removeScripts from './remove-scripts' import removeNoscripts from './remove-noscripts' diff --git a/src/freeze-dry/inline-images.js b/src/freeze-dry/inline-images.js index 28ccd02d3..833c3c09c 100644 --- a/src/freeze-dry/inline-images.js +++ b/src/freeze-dry/inline-images.js @@ -1,4 +1,4 @@ -import whenAllSettled from 'src/util/when-all-settled' +import whenAllSettled from 'when-all-settled' import { inlineUrlsInAttributes } from './common' diff --git a/src/freeze-dry/inline-styles.js b/src/freeze-dry/inline-styles.js index 7f7938e34..5d7e1e9bf 100644 --- a/src/freeze-dry/inline-styles.js +++ b/src/freeze-dry/inline-styles.js @@ -1,4 +1,4 @@ -import whenAllSettled from 'src/util/when-all-settled' +import whenAllSettled from 'when-all-settled' import { urlToDataUri } from './common' diff --git a/src/page-analysis/background/index.js b/src/page-analysis/background/index.js index b1c87ef8d..bc55cfdf7 100644 --- a/src/page-analysis/background/index.js +++ b/src/page-analysis/background/index.js @@ -4,7 +4,7 @@ import { dataURLToBlob } from 'blob-util' import { whenPageDOMLoaded } from 'src/util/tab-events' import { remoteFunction } from 'src/util/webextensionRPC' -import whenAllSettled from 'src/util/when-all-settled' +import whenAllSettled from 'when-all-settled' import db from 'src/pouchdb' import updateDoc from 'src/util/pouchdb-update-doc' diff --git a/src/util/when-all-settled.js b/src/util/when-all-settled.js deleted file mode 100644 index b0547c9c7..000000000 --- a/src/util/when-all-settled.js +++ /dev/null @@ -1,32 +0,0 @@ -// Like Promise.all, but it does not mind if any of the promises reject. - - -// By default, log rejections to the console when not in production mode. -const debugEnabled = ( - process && process.env && process.env.NODE_ENV !== 'production' -) -const defaultRejectionHandler = debugEnabled - ? error => { console.error(error) } - : () => {} - -// Creates a Promise that resolves when all promises passed to it have settled -// (= either resolved or rejected). This is almost the same as Promise.all, -// except it does not reject when some of the given promises reject. -// -// Arguments: -// - promises: an array of Promises to wait for. -// - options: { -// onRejection (optional): -// A rejection handler attached to each given promise. -// Note: if it throws an error, the returned promise rejects. -// } -// -// Returns: a Promise. -export default function whenAllSettled(promises, { - onRejection = defaultRejectionHandler, -} = {}) { - return Promise.all( - // Map each promise to a promise that never rejects. - promises.map(p => Promise.resolve(p).catch(onRejection)) - ) -} diff --git a/yarn.lock b/yarn.lock index 166aa1ea5..8e71f57e5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8325,6 +8325,12 @@ whatwg-url@^4.3.0: tr46 "~0.0.3" webidl-conversions "^3.0.0" +when-all-settled@^0.1.1: + version "0.1.1" + resolved "https://registry.yarnpkg.com/when-all-settled/-/when-all-settled-0.1.1.tgz#369bcfd142ed1f269174b8f0b6db1c87063c6113" + dependencies: + postinstall-build "^3.0.1" + when@3.7.7: version "3.7.7" resolved "https://registry.yarnpkg.com/when/-/when-3.7.7.tgz#aba03fc3bb736d6c88b091d013d8a8e590d84718" From a5ba6f1e846226ccf65aeec85ca05a4b0b0db222 Mon Sep 17 00:00:00 2001 From: Gerben Date: Fri, 14 Jul 2017 00:39:54 +0200 Subject: [PATCH 2/4] Spin off src/util/response-to-data-uri. https://www.npmjs.com/package/response-to-data-url --- package.json | 1 + src/freeze-dry/common.js | 4 ++-- src/freeze-dry/common.test.js | 6 +++--- src/page-analysis/background/get-fav-icon.js | 4 ++-- src/util/response-to-data-uri.js | 11 ----------- yarn.lock | 6 ++++++ 6 files changed, 14 insertions(+), 18 deletions(-) delete mode 100644 src/util/response-to-data-uri.js diff --git a/package.json b/package.json index c5dc9c0b7..d2fd1df5c 100644 --- a/package.json +++ b/package.json @@ -43,6 +43,7 @@ "redux-observable": "^0.14.1", "redux-query-sync": "^0.1.4", "redux-thunk": "^2.2.0", + "response-to-data-url": "^0.1.0", "rxjs": "^5.4.1", "semantic-ui-css": "git+https://github.com/Treora/semantic-ui-css.git#1d2237f", "semantic-ui-react": "^0.70.0", diff --git a/src/freeze-dry/common.js b/src/freeze-dry/common.js index f73cd3669..2dd6c6298 100644 --- a/src/freeze-dry/common.js +++ b/src/freeze-dry/common.js @@ -1,4 +1,4 @@ -import responseToDataUri from 'src/util/response-to-data-uri' +import responseToDataUrl from 'response-to-data-url' import whenAllSettled from 'when-all-settled' @@ -9,7 +9,7 @@ export function removeNode(node) { export async function urlToDataUri(url) { try { const response = await fetch(url, {cache: 'force-cache'}) - const dataUri = await responseToDataUri(response) + const dataUri = await responseToDataUrl(response) return dataUri } catch (err) { return 'about:invalid' diff --git a/src/freeze-dry/common.test.js b/src/freeze-dry/common.test.js index f0319857a..5af78530c 100644 --- a/src/freeze-dry/common.test.js +++ b/src/freeze-dry/common.test.js @@ -1,7 +1,7 @@ /* eslint-env jest */ import { inlineUrlsInAttributes, urlToDataUri, removeNode } from 'src/freeze-dry/common' -import * as responseToDataUri from 'src/util/response-to-data-uri' +import * as responseToDataUrl from 'response-to-data-url' import { dataURLToBlob } from 'blob-util' @@ -26,7 +26,7 @@ describe('removeNode', () => { describe('urlToDataUri', () => { test('should return a dataUri given a URL', async () => { const someDataUri = 'data:text/html,

bananas

' - const spy = jest.spyOn(responseToDataUri, 'default').mockImplementation(async () => { + const spy = jest.spyOn(responseToDataUrl, 'default').mockImplementation(async () => { return someDataUri }) const dataUri = await urlToDataUri('https://example.com/page') @@ -35,7 +35,7 @@ describe('urlToDataUri', () => { }) test('should return a "about:invalid" upon failure', async () => { - const spy = jest.spyOn(responseToDataUri, 'default').mockImplementation(async () => { + const spy = jest.spyOn(responseToDataUrl, 'default').mockImplementation(async () => { throw new Error('mock error') }) const dataUri = await urlToDataUri('http://example.com') diff --git a/src/page-analysis/background/get-fav-icon.js b/src/page-analysis/background/get-fav-icon.js index 8fbeba1c5..ce2763fc5 100644 --- a/src/page-analysis/background/get-fav-icon.js +++ b/src/page-analysis/background/get-fav-icon.js @@ -1,4 +1,4 @@ -import responseToDataURI from 'src/util/response-to-data-uri' +import responseToDataUrl from 'response-to-data-url' // Get a tab's fav-icon (website logo) as a data URI async function getFavIcon({tabId}) { @@ -9,7 +9,7 @@ async function getFavIcon({tabId}) { } const response = await fetch(tab.favIconUrl) - const dataURI = await responseToDataURI(response) + const dataURI = await responseToDataUrl(response) return dataURI } diff --git a/src/util/response-to-data-uri.js b/src/util/response-to-data-uri.js deleted file mode 100644 index c332fb123..000000000 --- a/src/util/response-to-data-uri.js +++ /dev/null @@ -1,11 +0,0 @@ -// Turn a fetch() response into data URI (does this have to be so convoluted?) -export default function responseToDataURI(response) { - return response.blob().then( - blob => new Promise((resolve, reject) => { - const reader = new FileReader() - reader.onload = () => resolve(reader.result) - reader.onerror = () => reject(reader.error) - reader.readAsDataURL(blob) - }) - ) -} diff --git a/yarn.lock b/yarn.lock index 8e71f57e5..9e9506767 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7131,6 +7131,12 @@ resolve@^1.1.3, resolve@^1.1.4, resolve@^1.1.6, resolve@^1.1.7, resolve@^1.3.2, dependencies: path-parse "^1.0.5" +response-to-data-url@^0.1.0: + version "0.1.0" + resolved "https://registry.yarnpkg.com/response-to-data-url/-/response-to-data-url-0.1.0.tgz#da1eb5724d114bd6568dda890acfbc3f905663ab" + dependencies: + postinstall-build "^3.0.1" + restore-cursor@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/restore-cursor/-/restore-cursor-1.0.1.tgz#34661f46886327fed2991479152252df92daa541" From 95fcbd0924cab20253a128804ed64aadf0a6fc3f Mon Sep 17 00:00:00 2001 From: Gerben Date: Fri, 14 Jul 2017 00:46:13 +0200 Subject: [PATCH 3/4] Consistently rename data URI -> data URL. Neither identifier nor locator fits the meaning very well (is it both?), but data URL is the term used commonly and originally (RFC 2397). --- src/activity-logger/index.js | 2 +- src/freeze-dry/common.js | 20 +++++------ src/freeze-dry/common.test.js | 34 +++++++++---------- src/freeze-dry/fix-links.test.js | 6 ++-- src/freeze-dry/inline-styles.js | 12 +++---- src/freeze-dry/inline-styles.test.js | 20 +++++------ src/freeze-dry/set-content-security-policy.js | 2 +- src/overview/components/ImgFromPouch.jsx | 10 +++--- src/page-analysis/background/get-fav-icon.js | 6 ++-- src/page-analysis/background/index.js | 12 +++---- .../background/make-screenshot.js | 4 +-- src/page-viewer/index.js | 4 +-- src/popup/popup.js | 4 +-- src/pouchdb.js | 8 ++--- 14 files changed, 72 insertions(+), 72 deletions(-) diff --git a/src/activity-logger/index.js b/src/activity-logger/index.js index 2adddc3db..3222bb352 100644 --- a/src/activity-logger/index.js +++ b/src/activity-logger/index.js @@ -24,7 +24,7 @@ export function generateVisitDocId({timestamp, nonce} = {}) { // Tell whether a page can be stored. export function isLoggable({url}) { - // Only http(s) pages. Ignoring data uris, newtab, ... + // Only http(s) pages. Ignoring data URLs, newtab, ... const loggableUrlPattern = /^https?:\/\// return loggableUrlPattern.test(url) } diff --git a/src/freeze-dry/common.js b/src/freeze-dry/common.js index 2dd6c6298..41035fcad 100644 --- a/src/freeze-dry/common.js +++ b/src/freeze-dry/common.js @@ -6,18 +6,18 @@ export function removeNode(node) { node.parentNode.removeChild(node) } -export async function urlToDataUri(url) { +export async function urlToDataUrl(url) { try { const response = await fetch(url, {cache: 'force-cache'}) - const dataUri = await responseToDataUrl(response) - return dataUri + const dataUrl = await responseToDataUrl(response) + return dataUrl } catch (err) { return 'about:invalid' } } // Find all URLs in the specified attribute(s) of the specified elements, fetch -// their contents, and replace the URL with the content encoded as a data URI. +// their contents, and replace the URL with the content encoded as a data URL. // The elements argument can be a query selector string if rootElement is given. export async function inlineUrlsInAttributes({ elements, @@ -44,17 +44,17 @@ export async function inlineUrlsInAttributes({ const urls = attrToUrls(value, attribute) // Fetch (hopefully from cache) the resource for each URL. - const dataUriPs = urls.map(async url => { + const dataUrlPs = urls.map(async url => { const absoluteUrl = new URL(url, docUrl) - const dataUri = await urlToDataUri(absoluteUrl) - return dataUri + const dataUrl = await urlToDataUrl(absoluteUrl) + return dataUrl }) - const dataUris = await Promise.all(dataUriPs) + const dataUrls = await Promise.all(dataUrlPs) - // Replace the URLs in the attribute value with the data URIs. + // Replace the URLs in the attribute value with the data URLs. let newValue = value for (let i = 0; i < urls.length; i++) { - newValue = newValue.replace(urls[i], dataUris[i]) + newValue = newValue.replace(urls[i], dataUrls[i]) } if (newValue !== value) { element.setAttribute(attribute, newValue) diff --git a/src/freeze-dry/common.test.js b/src/freeze-dry/common.test.js index 5af78530c..2b91720a1 100644 --- a/src/freeze-dry/common.test.js +++ b/src/freeze-dry/common.test.js @@ -1,11 +1,11 @@ /* eslint-env jest */ -import { inlineUrlsInAttributes, urlToDataUri, removeNode } from 'src/freeze-dry/common' +import { inlineUrlsInAttributes, urlToDataUrl, removeNode } from 'src/freeze-dry/common' import * as responseToDataUrl from 'response-to-data-url' import { dataURLToBlob } from 'blob-util' -const imageDataUri = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAAAAAA6fptVAAAACklEQVR4nGNiAAAABgADNjd8qAAAAABJRU5ErkJggg==' +const imageDataUrl = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAAAAAA6fptVAAAACklEQVR4nGNiAAAABgADNjd8qAAAAABJRU5ErkJggg==' beforeEach(() => { fetch.resetMocks() @@ -23,14 +23,14 @@ describe('removeNode', () => { }) }) -describe('urlToDataUri', () => { - test('should return a dataUri given a URL', async () => { - const someDataUri = 'data:text/html,

bananas

' +describe('urlToDataUrl', () => { + test('should return a dataUrl given a URL', async () => { + const someDataUrl = 'data:text/html,

bananas

' const spy = jest.spyOn(responseToDataUrl, 'default').mockImplementation(async () => { - return someDataUri + return someDataUrl }) - const dataUri = await urlToDataUri('https://example.com/page') - expect(dataUri).toBe(someDataUri) + const dataUrl = await urlToDataUrl('https://example.com/page') + expect(dataUrl).toBe(someDataUrl) spy.mockRestore() }) @@ -38,15 +38,15 @@ describe('urlToDataUri', () => { const spy = jest.spyOn(responseToDataUrl, 'default').mockImplementation(async () => { throw new Error('mock error') }) - const dataUri = await urlToDataUri('http://example.com') - expect(dataUri).toBe('about:invalid') + const dataUrl = await urlToDataUrl('http://example.com') + expect(dataUrl).toBe('about:invalid') spy.mockRestore() }) test('should return a "about:invalid" when fetching fails', async () => { fetch.mockRejectOnce() - const dataUri = await urlToDataUri('http://example.com') - expect(dataUri).toBe('about:invalid') + const dataUrl = await urlToDataUrl('http://example.com') + expect(dataUrl).toBe('about:invalid') }) }) @@ -56,10 +56,10 @@ describe('inlineUrlsInAttributes', () => { let imageBlob beforeAll(async () => { - imageBlob = await dataURLToBlob(imageDataUri) + imageBlob = await dataURLToBlob(imageDataUrl) }) - test('should change the URL in tag to a dataUri', async () => { + test('should change the URL in tag to a dataUrl', async () => { fetch.mockResponseOnce(imageBlob) const doc = parser.parseFromString( 'background', @@ -68,10 +68,10 @@ describe('inlineUrlsInAttributes', () => { const rootElement = doc.documentElement await inlineUrlsInAttributes({elements: 'img', attributes: 'src', rootElement, docUrl}) expect(rootElement.querySelector('img').getAttribute('data-original-src')).toBe('public/image/background.png') - expect(rootElement.querySelector('img').getAttribute('src')).toBe(imageDataUri) + expect(rootElement.querySelector('img').getAttribute('src')).toBe(imageDataUrl) }) - test('should change the URL in the tag to a dataUri', async () => { + test('should change the URL in the tag to a dataUrl', async () => { fetch.mockResponseOnce(imageBlob) const doc = parser.parseFromString( '', @@ -80,7 +80,7 @@ describe('inlineUrlsInAttributes', () => { const rootElement = doc.documentElement await inlineUrlsInAttributes({elements: 'link', attributes: 'href', rootElement, docUrl}) expect(rootElement.querySelector('link').getAttribute('data-original-href')).toBe('public/image/favicon.ico') - expect(rootElement.querySelector('link').getAttribute('href')).toBe(imageDataUri) + expect(rootElement.querySelector('link').getAttribute('href')).toBe(imageDataUrl) }) test('should remove the attribute integrity from the tag', async () => { diff --git a/src/freeze-dry/fix-links.test.js b/src/freeze-dry/fix-links.test.js index 9111a0e08..cc9ac19d5 100644 --- a/src/freeze-dry/fix-links.test.js +++ b/src/freeze-dry/fix-links.test.js @@ -53,10 +53,10 @@ describe('fixLinks', () => { }) test('should not alter data urls in href attribute', async () => { - const datauri = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAAAAAA6fptVAAAACklEQVR4nGNiAAAABgADNjd8qAAAAABJRU5ErkJggg==' + const dataUrl = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAAAAAA6fptVAAAACklEQVR4nGNiAAAABgADNjd8qAAAAABJRU5ErkJggg==' const rootElement = window.document.createElement('div') - rootElement.innerHTML = `Link` + rootElement.innerHTML = `Link` await fixLinks({rootElement, docUrl}) - expect(rootElement.querySelector('*[href]').getAttribute('href')).toBe(datauri) + expect(rootElement.querySelector('*[href]').getAttribute('href')).toBe(dataUrl) }) }) diff --git a/src/freeze-dry/inline-styles.js b/src/freeze-dry/inline-styles.js index 5d7e1e9bf..a48bf6073 100644 --- a/src/freeze-dry/inline-styles.js +++ b/src/freeze-dry/inline-styles.js @@ -1,9 +1,9 @@ import whenAllSettled from 'when-all-settled' -import { urlToDataUri } from './common' +import { urlToDataUrl } from './common' // Finds all url(...) occurrances in a string of CSS, then fetches and inlines -// them as data URIs. +// them as data URLs. // Returns the processed (and possibly much larger) string of CSS. async function inlineStylesheetContents({stylesheetText, stylesheetUrl}) { const cssFindUrlsPattern = /url\s*\(\s*('|")?\s*([^"')]+?)\s*\1\s*\)/ig @@ -18,14 +18,14 @@ async function inlineStylesheetContents({stylesheetText, stylesheetUrl}) { ? new URL(match[2], stylesheetUrl) : undefined }) - const dataUris = await Promise.all(urls.map(urlToDataUri)) - dataUris.forEach((dataUri, i) => { - stylesheetText = stylesheetText.replace(cssUrls[i], `url(${dataUri})`) + const dataUrls = await Promise.all(urls.map(urlToDataUrl)) + dataUrls.forEach((dataUrl, i) => { + stylesheetText = stylesheetText.replace(cssUrls[i], `url(${dataUrl})`) }) return stylesheetText } -// In every tag, inline the stylesheet as a data URI, +// In every tag, inline the stylesheet as a data URL, // and inline every URL within that stylesheet. async function inlineLinkedStylesheets({rootElement, docUrl}) { const querySelector = 'link[rel*="stylesheet"][href]' diff --git a/src/freeze-dry/inline-styles.test.js b/src/freeze-dry/inline-styles.test.js index 6cc94c466..65e4b42ff 100644 --- a/src/freeze-dry/inline-styles.test.js +++ b/src/freeze-dry/inline-styles.test.js @@ -5,14 +5,14 @@ import * as common from 'src/freeze-dry/common' import { dataURLToBlob } from 'blob-util' -const imageDataUri = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAAAAAA6fptVAAAACklEQVR4nGNiAAAABgADNjd8qAAAAABJRU5ErkJggg==' +const imageDataUrl = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAAAAAA6fptVAAAACklEQVR4nGNiAAAABgADNjd8qAAAAABJRU5ErkJggg==' describe('inlineStyles', () => { const parser = new DOMParser() let imageBlob beforeAll(async () => { - imageBlob = await dataURLToBlob(imageDataUri) + imageBlob = await dataURLToBlob(imageDataUrl) }) test('should return . - linkEl.parentNode.replaceChild(styleEl, linkEl) - }) - await whenAllSettled(jobs) -} - -// In every block, inline any URLs it contains. -async function inlineStyleTagContents({rootElement, docUrl}) { - const querySelector = 'style[type="text/css"],style:not([type])' - const styleElements = Array.from(rootElement.querySelectorAll(querySelector)) - const jobs = styleElements.map(async styleEl => { - let stylesheetText = styleEl.innerHTML - stylesheetText = await inlineStylesheetContents({ - stylesheetText, - stylesheetUrl: docUrl, - }) - styleEl.innerHTML = stylesheetText - }) - await whenAllSettled(jobs) -} - -// In every inline style, inline any URLs it contains. -async function inlineInlineStyleContents({rootElement, docUrl}) { - const querySelector = '*[style]' - const elements = Array.from(rootElement.querySelectorAll(querySelector)) - const jobs = elements.map(async element => { - let inlineStyleText = element.getAttribute('style') - inlineStyleText = await inlineStylesheetContents({ - stylesheetText: inlineStyleText, - stylesheetUrl: docUrl, - }) - element.setAttribute('style', inlineStyleText) - }) - await whenAllSettled(jobs) -} - -export default async function inlineStyles({rootElement, docUrl}) { - const jobs = [ - inlineLinkedStylesheets({rootElement, docUrl}), - inlineStyleTagContents({rootElement, docUrl}), - inlineInlineStyleContents({rootElement, docUrl}), - ] - await whenAllSettled(jobs) -} diff --git a/src/freeze-dry/inline-styles.test.js b/src/freeze-dry/inline-styles.test.js deleted file mode 100644 index 65e4b42ff..000000000 --- a/src/freeze-dry/inline-styles.test.js +++ /dev/null @@ -1,78 +0,0 @@ -/* eslint-env jest */ - -import inlineStyles from 'src/freeze-dry/inline-styles' -import * as common from 'src/freeze-dry/common' -import { dataURLToBlob } from 'blob-util' - - -const imageDataUrl = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAAAAAA6fptVAAAACklEQVR4nGNiAAAABgADNjd8qAAAAABJRU5ErkJggg==' - -describe('inlineStyles', () => { - const parser = new DOMParser() - let imageBlob - - beforeAll(async () => { - imageBlob = await dataURLToBlob(imageDataUrl) - }) - - test('should return - -
-
- `, - 'text/html' - ) - const docUrl = 'https://example.com' - await inlineStyles({rootElement: doc.documentElement, docUrl}) - expect(spy).toHaveBeenCalled() - expect(doc.querySelector('style').innerHTML.trim()) - .toBe(`div{background-image: url(${styleSheetAsDataUrl});}`) - spy.mockRestore() - }) - - test('should convert the urls in a style attribute to data URLs', async () => { - const spy = jest.spyOn(common, 'urlToDataUrl').mockReturnValue(imageDataUrl) - const doc = parser.parseFromString( - '
', - 'text/html' - ) - const docUrl = 'https://example.com' - await inlineStyles({rootElement: doc.documentElement, docUrl}) - expect(spy).toHaveBeenCalled() - expect(doc.querySelector('div').getAttribute('style')) - .toBe(`background-image: url(${imageDataUrl});`) - spy.mockRestore() - }) -}) diff --git a/src/freeze-dry/remove-noscripts.js b/src/freeze-dry/remove-noscripts.js deleted file mode 100644 index f641d7fbf..000000000 --- a/src/freeze-dry/remove-noscripts.js +++ /dev/null @@ -1,8 +0,0 @@ -import { removeNode } from './common.js' - - -// Removes all