Skip to content

Commit

Permalink
Merge branch 'master' into production
Browse files Browse the repository at this point in the history
  • Loading branch information
nafees87n committed Jun 12, 2024
2 parents 6397adf + d0046cd commit 7d27bcd
Show file tree
Hide file tree
Showing 36 changed files with 267 additions and 1,623 deletions.
735 changes: 110 additions & 625 deletions app/package-lock.json

Large diffs are not rendered by default.

8 changes: 3 additions & 5 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
"dev": "REACT_APP_ENV=DEV npm start",
"emulated-dev": "REACT_APP_ENV=EMULATOR npm start",
"preview": "npm run build && vite preview",
"type-check": "tsc --noEmit",
"postinstall": "patch-package"
"type-check": "tsc --noEmit"
},
"browserslist": [
">0.2%",
Expand Down Expand Up @@ -119,8 +118,8 @@
"redux-deep-persist": "^1.0.6",
"redux-persist": "^6.0.0",
"rehype-raw": "^7.0.0",
"rrweb": "2.0.0-alpha.11",
"rrweb-player": "2.0.0-alpha.11",
"rrweb": "2.0.0-alpha.14",
"rrweb-player": "2.0.0-alpha.14",
"semver": "^7.5.4",
"styled-components": "^6.1.8",
"ts-loader": "^9.3.0",
Expand Down Expand Up @@ -154,7 +153,6 @@
"eslint": "^8.57.0",
"eslint-config-react-app": "^7.0.1",
"less": "^4.2.0",
"patch-package": "^8.0.0",
"sass": "^1.58.3",
"source-map-loader": "^3.0.1",
"typescript": "^4.7.3",
Expand Down
120 changes: 0 additions & 120 deletions app/patches/rrweb-player+2.0.0-alpha.11.patch

This file was deleted.

14 changes: 7 additions & 7 deletions browser-extension/mv3/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions browser-extension/mv3/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,17 @@ export default [
plugins: commonPlugins,
},
{
input: "src/client-scripts/index.ts",
input: "src/page-scripts/sessionRecorderHelper.js",
output: {
file: `${OUTPUT_DIR}/client.js`,
file: `${OUTPUT_DIR}/page-scripts/sessionRecorderHelper.ps.js`,
format: "iife",
},
plugins: commonPlugins,
},
{
input: "src/page-scripts/ajaxRequestInterceptor.js",
output: {
file: `${OUTPUT_DIR}/page-scripts/ajaxRequestInterceptor.ps.js`,
format: "iife",
},
plugins: commonPlugins,
Expand Down
2 changes: 0 additions & 2 deletions browser-extension/mv3/src/client-scripts/index.ts

This file was deleted.

12 changes: 11 additions & 1 deletion browser-extension/mv3/src/content-scripts/app/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { initMessageHandler, initExtensionMessageListener } from "./messageHandler";
import { EXTENSION_MESSAGES } from "common/constants";
import { isExtensionEnabled } from "../../utils";
import { initMessageHandler } from "./messageHandler";
import { initSessionRecording } from "../common/sessionRecorder";
import { initExtensionMessageListener } from "../common/extensionMessageListener";

document.documentElement.setAttribute("rq-ext-version", chrome.runtime.getManifest()["version"]);

Expand All @@ -10,3 +14,9 @@ document.documentElement.setAttribute("rq-ext-id", chrome.runtime.id);

initMessageHandler();
initExtensionMessageListener();
isExtensionEnabled().then((isExtensionStatusEnabled) => {
if (isExtensionStatusEnabled) {
chrome.runtime.sendMessage({ action: EXTENSION_MESSAGES.HANDSHAKE_CLIENT });
initSessionRecording();
}
});
10 changes: 0 additions & 10 deletions browser-extension/mv3/src/content-scripts/app/messageHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,3 @@ export const initMessageHandler = () => {
}
);
};

export const initExtensionMessageListener = () => {
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
switch (message.action) {
case EXTENSION_MESSAGES.NOTIFY_TEST_RULE_REPORT_UPDATED:
sendExtensionMessage(message);
break;
}
});
};
4 changes: 3 additions & 1 deletion browser-extension/mv3/src/content-scripts/client/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { EXTENSION_MESSAGES } from "common/constants";
import { initSessionRecording } from "./sessionRecorder";
import { initSessionRecording } from "../common/sessionRecorder";
import { Variable, getVariable } from "../../service-worker/variable";
import { initPageScriptMessageListener } from "./pageScriptMessageListener";
import { initTestRuleHandler } from "./testRuleHandler";
import { initExtensionMessageListener } from "../common/extensionMessageListener";

if (document.doctype?.name === "html" || document.contentType?.includes("html")) {
initExtensionMessageListener();
getVariable<boolean>(Variable.IS_EXTENSION_ENABLED, true).then((isExtensionStatusEnabled) => {
if (isExtensionStatusEnabled) {
chrome.runtime.sendMessage({ action: EXTENSION_MESSAGES.HANDSHAKE_CLIENT });
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { EXTENSION_MESSAGES } from "common/constants";
import { sendExtensionMessage } from "../app/messageHandler";

export const initExtensionMessageListener = () => {
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
switch (message.action) {
case EXTENSION_MESSAGES.NOTIFY_TEST_RULE_REPORT_UPDATED:
sendExtensionMessage(message);
break;

case EXTENSION_MESSAGES.CLIENT_PAGE_LOADED:
chrome.runtime.sendMessage({ action: EXTENSION_MESSAGES.CLIENT_PAGE_LOADED });
break;
}
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ export const initSessionRecording = () => {
case CLIENT_MESSAGES.START_RECORDING:
sendStartRecordingEvent(message.payload);
break;
case EXTENSION_MESSAGES.CLIENT_PAGE_LOADED:
if (!sessionRecorderState.isRecording) {
chrome.runtime.sendMessage({ action: EXTENSION_MESSAGES.CLIENT_PAGE_LOADED });
}
break;
}
});

Expand Down
49 changes: 29 additions & 20 deletions browser-extension/mv3/src/service-worker/services/clientHandler.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,44 @@
import { generateUrlPattern } from "../../utils";
import { WEB_URL, OTHER_WEB_URLS } from "../../../../config/dist/config.build.json";
import { isExtensionEnabled } from "./utils";
import { isExtensionEnabled } from "../../utils";
import { Variable, onVariableChange } from "../variable";
import { RequestRulePair, ResponseRulePair, RuleType } from "common/types";
import rulesStorageService from "../../rulesStorageService";

const CLIENT_SCRIPT_ID = "client-script";
const excludeMatchesPatterns = [WEB_URL, ...OTHER_WEB_URLS].map(generateUrlPattern).filter((pattern) => !!pattern);

const CLIENT_SCRIPTS: chrome.scripting.RegisteredContentScript[] = [
{
id: "page-script-ajaxInterceptor",
js: ["page-scripts/ajaxRequestInterceptor.ps.js"],
world: "MAIN",
allFrames: true,
persistAcrossSessions: false,
matches: ["http://*/*", "https://*/*"],
runAt: "document_start",
excludeMatches: excludeMatchesPatterns,
},
{
id: "page-script-sessionRecorder",
js: ["page-scripts/sessionRecorderHelper.ps.js"],
world: "MAIN",
persistAcrossSessions: false,
matches: ["http://*/*", "https://*/*"],
runAt: "document_start",
},
];

declare const window: {
responseRules: Record<string, unknown>[];
requestRules: Record<string, unknown>[];
[key: string]: any;
};

/** Loading AJAX Interceptor ASAP */
const registerClientScript = async () => {
/** Loading Client scripts ASAP */
const registerClientScripts = async () => {
console.log("[registerClientScript]");
chrome.scripting
.registerContentScripts([
{
id: CLIENT_SCRIPT_ID,
js: ["client.js"],
world: "MAIN",
allFrames: true,
persistAcrossSessions: false,
matches: ["http://*/*", "https://*/*"],
runAt: "document_start",
excludeMatches: excludeMatchesPatterns,
},
])
.registerContentScripts(CLIENT_SCRIPTS)
.then(() => {
console.log("[registerClientScript]");
chrome.scripting
Expand All @@ -39,10 +48,10 @@ const registerClientScript = async () => {
.catch((err) => console.warn("[unregisterClientScript]", "unexpected error", err));
};

const unregisterClientScript = async () => {
const unregisterClientScripts = async () => {
console.log("[unregisterClientScript]");
return chrome.scripting
.unregisterContentScripts({ ids: [CLIENT_SCRIPT_ID] })
.unregisterContentScripts({ ids: CLIENT_SCRIPTS.map((script) => script.id) })
.then(() => {
console.log("[unregisterClientScript]", "unregisterClientScript complete");
chrome.scripting
Expand All @@ -55,9 +64,9 @@ const unregisterClientScript = async () => {
const setupClientScript = async (isExtensionStatusEnabled: boolean) => {
console.log("[initClientHandler.setupClientScript]", { isExtensionEnabled });
if (isExtensionStatusEnabled) {
registerClientScript();
registerClientScripts();
} else {
unregisterClientScript();
unregisterClientScripts();
}
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { onVariableChange, setVariable, Variable } from "../variable";
import extensionIconManager from "./extensionIconManager";
import { isExtensionEnabled } from "./utils";
import { isExtensionEnabled } from "../../utils";

// TODO: fix circular dependency
// import { sendMessageToApp } from "./messageHandler";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CLIENT_MESSAGES, EXTENSION_MESSAGES } from "common/constants";
import { checkIfNoRulesPresent, getRulesAndGroups } from "common/rulesStore";
import { getAppTabs, isExtensionEnabled, toggleExtensionStatus } from "./utils";
import { getAppTabs, toggleExtensionStatus } from "./utils";
// import { handleRuleExecutionsOnClientPageLoad } from "./rulesManager";
import { applyScriptRules } from "./scriptRuleHandler";
import {
Expand All @@ -24,6 +24,7 @@ import {
saveTestRuleResult,
} from "./testThisRuleHandler";
import ruleExecutionHandler from "./ruleExecutionHandler";
import { isExtensionEnabled } from "../../utils";

// TODO: relay this message from content script to app, so UI could be updated immediately
export const sendMessageToApp = (messageObject: unknown, callback?: () => void) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import config from "common/config";
import { getEnabledRules, onRuleOrGroupChange } from "common/rulesStore";
import { getVariable, onVariableChange, setVariable, Variable } from "../variable";
import { isExtensionEnabled } from "./utils";
import { isExtensionEnabled } from "../../utils";
import { TAB_SERVICE_DATA, tabService } from "./tabService";
import { SessionRuleType } from "./requestProcessor/types";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import { CLIENT_MESSAGES } from "common/constants";
import { getRecord } from "common/storage";
import { AutoRecordingMode, SessionRecordingConfig, SourceKey, SourceOperator } from "common/types";
import { matchSourceUrl } from "./ruleMatcher";
import { injectWebAccessibleScript, isExtensionEnabled } from "./utils";
import { injectWebAccessibleScript } from "./utils";
import config from "common/config";
import { TAB_SERVICE_DATA, tabService } from "./tabService";
import extensionIconManager from "./extensionIconManager";
import { isExtensionEnabled } from "../../utils";

const CONFIG_STORAGE_KEY = "sessionRecordingConfig";

Expand Down
8 changes: 2 additions & 6 deletions browser-extension/mv3/src/service-worker/services/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ScriptAttributes, ScriptCodeType, ScriptObject, ScriptType } from "common/types";
import { getVariable, setVariable, Variable } from "../variable";
import { getAllSupportedWebURLs } from "../../utils";
import { setVariable, Variable } from "../variable";
import { getAllSupportedWebURLs, isExtensionEnabled } from "../../utils";
import { stopRecordingOnAllTabs } from "./sessionRecording";

/* Do not refer any external variable in below function other than arguments */
Expand Down Expand Up @@ -159,10 +159,6 @@ export const isNonBrowserTab = (tabId: number): boolean => {
return tabId === chrome.tabs.TAB_ID_NONE;
};

export const isExtensionEnabled = async (): Promise<boolean> => {
return await getVariable<boolean>(Variable.IS_EXTENSION_ENABLED, true);
};

export const toggleExtensionStatus = async () => {
const extensionEnabledStatus = await isExtensionEnabled();

Expand Down
5 changes: 5 additions & 0 deletions browser-extension/mv3/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { SourceKey, SourceOperator, UrlSource } from "common/types";
import config from "common/config";
import { matchSourceUrl } from "./service-worker/services/ruleMatcher";
import { Variable, getVariable } from "./service-worker/variable";

export const formatDate = (dateInMillis: number, format: string): string => {
if (dateInMillis && format === "yyyy-mm-dd") {
Expand Down Expand Up @@ -62,3 +63,7 @@ export const getUrlObject = (url: string): URL | undefined => {
return null;
}
};

export const isExtensionEnabled = async (): Promise<boolean> => {
return await getVariable<boolean>(Variable.IS_EXTENSION_ENABLED, true);
};
Loading

0 comments on commit 7d27bcd

Please sign in to comment.