Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanups post CSS support #345

Merged
merged 2 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/js/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export const ORIGIN_TYPE = Object.freeze({
export type Origin = keyof typeof ORIGIN_TYPE;

// Firefox and Safari currently do not support CompressionStream/showSaveFilePicker
export const DOWNLOAD_JS_ENABLED =
export const DOWNLOAD_SRC_ENABLED =
'CompressionStream' in window && 'showSaveFilePicker' in window;

export const MANIFEST_TIMEOUT = 45000;
Expand Down
16 changes: 6 additions & 10 deletions src/js/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import {
MESSAGE_TYPE,
DOWNLOAD_JS_ENABLED,
DOWNLOAD_SRC_ENABLED,
STATES,
Origin,
ORIGIN_TYPE,
Expand Down Expand Up @@ -179,7 +179,7 @@ function handleManifestNode(manifestNode: HTMLScriptElement): void {
}

sendMessageToBackground(messagePayload, response => {
// then start processing of it's JS
// then start processing its JS/CSS
if (response.valid) {
if (manifestTimeoutID !== '') {
clearTimeout(manifestTimeoutID);
Expand Down Expand Up @@ -225,16 +225,12 @@ export const processFoundElements = async (version: string): Promise<void> => {
updateCurrentState(STATES.VALID);
}
} else {
if (response.type === 'EXTENSION') {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was unused

updateCurrentState(STATES.RISK);
} else {
updateCurrentState(STATES.INVALID, `Invalid Tag ${tagIdentifier}`);
}
updateCurrentState(STATES.INVALID, `Invalid Tag ${tagIdentifier}`);
}
sendMessageToBackground({
type: MESSAGE_TYPE.DEBUG,
log:
'processed JS with SRC response is ' +
'processed SRC response is ' +
JSON.stringify(response).substring(0, 500),
src: tagIdentifier,
});
Expand Down Expand Up @@ -324,7 +320,7 @@ export function storeFoundElement(element: HTMLElement): void {
updateCurrentState(STATES.INVALID, 'blob: src');
return;
}
if (script.src !== '' || script.innerHTML !== '') {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not necessary because CSP prevents inline scripts.

if (script.src !== '') {
handleScriptNode(script);
}
} else if (element.nodeName.toLowerCase() === 'style') {
Expand Down Expand Up @@ -458,7 +454,7 @@ export function startFor(origin: Origin, config: ContentScriptConfig): void {
}

chrome.runtime.onMessage.addListener(request => {
if (request.greeting === 'downloadSource' && DOWNLOAD_JS_ENABLED) {
if (request.greeting === 'downloadSource' && DOWNLOAD_SRC_ENABLED) {
downloadSrc();
} else if (request.greeting === 'nocacheHeaderFound') {
updateCurrentState(
Expand Down
8 changes: 4 additions & 4 deletions src/js/content/contentUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
import alertBackgroundOfImminentFetch from './alertBackgroundOfImminentFetch';

import {TagDetails} from '../content';
import {DOWNLOAD_JS_ENABLED, MESSAGE_TYPE} from '../config';
import {DOWNLOAD_SRC_ENABLED, MESSAGE_TYPE} from '../config';
import genSourceText from './genSourceText';
import {sendMessageToBackground} from '../shared/sendMessageToBackground';
import {getCurrentOrigin} from './updateCurrentState';
import downloadJSArchive from './downloadJSArchive';
import downloadArchive from './downloadArchive';

const SOURCE_SCRIPTS_AND_STYLES = new Map();

Expand Down Expand Up @@ -40,7 +40,7 @@ async function processSrc(
// If this is missing it will cause a cache miss, resulting in invalidation.
headers: isServiceWorker ? {'Service-Worker': 'script'} : undefined,
});
if (DOWNLOAD_JS_ENABLED) {
if (DOWNLOAD_SRC_ENABLED) {
const fileNameArr = url.split('/');
const fileName = fileNameArr[fileNameArr.length - 1].split('?')[0];
const responseBody = sourceResponse.clone().body;
Expand Down Expand Up @@ -90,7 +90,7 @@ async function processSrc(
}

function downloadSrc(): void {
downloadJSArchive(SOURCE_SCRIPTS_AND_STYLES);
downloadArchive(SOURCE_SCRIPTS_AND_STYLES);
}

export {processSrc, downloadSrc};
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

export default async function downloadJSArchive(
export default async function downloadArchive(
sourceScripts: Map<string, ReadableStream>,
): Promise<void> {
const fileHandle = await window.showSaveFilePicker({
Expand Down
4 changes: 2 additions & 2 deletions src/js/popup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import {
DOWNLOAD_JS_ENABLED,
DOWNLOAD_SRC_ENABLED,
MESSAGE_TYPE,
ORIGIN_TYPE,
STATES,
Expand Down Expand Up @@ -105,7 +105,7 @@ function attachListeners(origin: string | null): void {
)[0];
const downloadSrcButton = document.getElementById('i18nDownloadSourceButton');

if (DOWNLOAD_JS_ENABLED) {
if (DOWNLOAD_SRC_ENABLED) {
const downloadPageSourceMenuItem = menuRowList[1];
downloadPageSourceMenuItem.addEventListener('click', () =>
updateDisplay('download'),
Expand Down
Loading