Initial commit
This commit is contained in:
42
README.md
Normal file
42
README.md
Normal file
@@ -0,0 +1,42 @@
|
||||
# Opportunities Extension
|
||||
|
||||
Extensao de navegador para adicionar o atalho "Opportunities Extension" nas paginas Oracle Fusion permitidas.
|
||||
|
||||
## Estrutura de desenvolvimento
|
||||
|
||||
- `src/content.js`: script unico mantido no projeto.
|
||||
- `scripts/build.mjs`: gera os pacotes especificos para cada navegador.
|
||||
- `dist/chromium/`: output para Google Chrome e Microsoft Edge.
|
||||
- `dist/firefox/`: output para Firefox.
|
||||
|
||||
## Build
|
||||
|
||||
Use o Node.js:
|
||||
|
||||
```bash
|
||||
npm run build
|
||||
```
|
||||
|
||||
O build recria `dist/chromium` e `dist/firefox` a partir da mesma fonte.
|
||||
|
||||
## Como carregar em modo desenvolvimento
|
||||
|
||||
### Chrome ou Microsoft Edge
|
||||
|
||||
1. Abra `chrome://extensions` ou `edge://extensions`.
|
||||
2. Ative o modo de desenvolvedor.
|
||||
3. Clique em "Carregar sem compactacao".
|
||||
4. Selecione a pasta `dist/chromium`.
|
||||
|
||||
### Firefox
|
||||
|
||||
1. Abra `about:debugging#/runtime/this-firefox`.
|
||||
2. Clique em "Carregar extensao temporaria".
|
||||
3. Selecione o arquivo `dist/firefox/manifest.json`.
|
||||
|
||||
## Paginas atendidas
|
||||
|
||||
- `https://eeho.fa.us2.oraclecloud.com/hcmUI/faces/FuseWelcome`
|
||||
- `https://eeho.fa.us2.oraclecloud.com/fscmUI/faces/FuseWelcome`
|
||||
|
||||
Ao encontrar o grupo `#yourapps_groupNode_sales`, a extensao adiciona o tile antes do item `.flat-grid-cell.flat-grid-cell-addicon`. Ao clicar no tile, exibe o alerta `Deu certo`.
|
||||
216
dist/chromium/background.js
vendored
Normal file
216
dist/chromium/background.js
vendored
Normal file
@@ -0,0 +1,216 @@
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
const ORACLE_DOMAIN = "eeho.fa.us2.oraclecloud.com";
|
||||
const ORACLE_COOKIE_URLS = [
|
||||
"https://eeho.fa.us2.oraclecloud.com/",
|
||||
"https://eeho.fa.us2.oraclecloud.com/hcmUI/faces/FuseWelcome",
|
||||
"https://eeho.fa.us2.oraclecloud.com/fscmUI/faces/FuseWelcome",
|
||||
"https://eeho.fa.us2.oraclecloud.com/fscmRestApi/tokenrelay"
|
||||
];
|
||||
const XSRF_COOKIE_NAME = "XSRF-TOKEN-US2DZ2V_F";
|
||||
const XSRF_COOKIE_PREFIX = "XSRF-TOKEN-";
|
||||
const runtimeApi = typeof browser !== "undefined" ? browser : chrome;
|
||||
|
||||
runtimeApi.runtime.onMessage.addListener((message, sender, sendResponse) => {
|
||||
if (!message || message.type !== "opportunitiesExtension.getXsrfToken") {
|
||||
return false;
|
||||
}
|
||||
|
||||
getXsrfTokenCookie()
|
||||
.then((result) => {
|
||||
sendResponse({
|
||||
ok: true,
|
||||
cookieName: result.cookie ? result.cookie.name : "",
|
||||
token: result.cookie ? result.cookie.value : "",
|
||||
matchedCookieNames: result.matchedCookieNames,
|
||||
lookupDetails: result.lookupDetails
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
sendResponse({
|
||||
ok: false,
|
||||
cookieName: "",
|
||||
token: "",
|
||||
matchedCookieNames: [],
|
||||
lookupDetails: [],
|
||||
error: error.message || "Unable to read cookies."
|
||||
});
|
||||
});
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
async function getXsrfTokenCookie() {
|
||||
const lookupDetails = [];
|
||||
const allCookies = [];
|
||||
const stores = await getCookieStores(lookupDetails);
|
||||
|
||||
for (const store of stores) {
|
||||
const exactCookie = await getExactCookieFromUrls(store.id, lookupDetails);
|
||||
|
||||
if (exactCookie) {
|
||||
allCookies.push(exactCookie);
|
||||
}
|
||||
}
|
||||
|
||||
for (const store of stores) {
|
||||
await collectCookies({
|
||||
name: XSRF_COOKIE_NAME,
|
||||
storeId: store.id
|
||||
}, allCookies, lookupDetails);
|
||||
}
|
||||
|
||||
for (const store of stores) {
|
||||
await collectCookies({
|
||||
domain: ORACLE_DOMAIN,
|
||||
storeId: store.id
|
||||
}, allCookies, lookupDetails);
|
||||
|
||||
await collectCookies({
|
||||
domain: `.${ORACLE_DOMAIN}`,
|
||||
storeId: store.id
|
||||
}, allCookies, lookupDetails);
|
||||
}
|
||||
|
||||
for (const store of stores) {
|
||||
for (const url of ORACLE_COOKIE_URLS) {
|
||||
await collectCookies({
|
||||
url,
|
||||
storeId: store.id
|
||||
}, allCookies, lookupDetails);
|
||||
}
|
||||
}
|
||||
|
||||
const uniqueCookies = dedupeCookies(allCookies);
|
||||
const xsrfCookies = uniqueCookies.filter((cookie) => cookie.name.startsWith(XSRF_COOKIE_PREFIX));
|
||||
const exactCookie = xsrfCookies.find((cookie) => cookie.name === XSRF_COOKIE_NAME);
|
||||
const hostCookie = xsrfCookies.find((cookie) => cookie.domain === ORACLE_DOMAIN || cookie.domain === `.${ORACLE_DOMAIN}`);
|
||||
|
||||
return {
|
||||
cookie: exactCookie || hostCookie || xsrfCookies[0] || null,
|
||||
matchedCookieNames: xsrfCookies.map((cookie) => `${cookie.name} (${cookie.domain}${cookie.path})`),
|
||||
lookupDetails
|
||||
};
|
||||
}
|
||||
|
||||
async function getExactCookieFromUrls(storeId, lookupDetails) {
|
||||
for (const url of ORACLE_COOKIE_URLS) {
|
||||
const cookie = await cookiesGet({
|
||||
url,
|
||||
name: XSRF_COOKIE_NAME,
|
||||
storeId
|
||||
});
|
||||
|
||||
lookupDetails.push(`${JSON.stringify({ url, name: XSRF_COOKIE_NAME, storeId })} => ${cookie ? "found" : "not found"}`);
|
||||
|
||||
if (cookie) {
|
||||
return cookie;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
async function getCookieStores(lookupDetails) {
|
||||
try {
|
||||
const stores = await cookiesGetAllCookieStores();
|
||||
lookupDetails.push(`getAllCookieStores => ${stores.length} store(s)`);
|
||||
return stores.length ? stores : [{ id: undefined }];
|
||||
} catch (error) {
|
||||
lookupDetails.push(`getAllCookieStores => unavailable (${error.message || "unknown error"})`);
|
||||
return [{ id: undefined }];
|
||||
}
|
||||
}
|
||||
|
||||
async function collectCookies(details, target, lookupDetails) {
|
||||
const cleanDetails = removeUndefinedValues(details);
|
||||
const cookies = await cookiesGetAll(cleanDetails);
|
||||
target.push(...cookies);
|
||||
lookupDetails.push(`${JSON.stringify(cleanDetails)} => ${cookies.length} cookie(s)`);
|
||||
}
|
||||
|
||||
function dedupeCookies(cookies) {
|
||||
const seen = new Set();
|
||||
|
||||
return cookies.filter((cookie) => {
|
||||
const key = `${cookie.name}|${cookie.domain}|${cookie.path}|${cookie.storeId || ""}`;
|
||||
|
||||
if (seen.has(key)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
seen.add(key);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
function cookiesGetAll(details) {
|
||||
if (runtimeApi.cookies.getAll.length <= 1) {
|
||||
return runtimeApi.cookies.getAll(details);
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
runtimeApi.cookies.getAll(details, (cookies) => {
|
||||
const lastError = runtimeApi.runtime.lastError;
|
||||
|
||||
if (lastError) {
|
||||
reject(new Error(lastError.message));
|
||||
return;
|
||||
}
|
||||
|
||||
resolve(cookies);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function cookiesGet(details) {
|
||||
const cleanDetails = removeUndefinedValues(details);
|
||||
|
||||
if (runtimeApi.cookies.get.length <= 1) {
|
||||
return runtimeApi.cookies.get(cleanDetails);
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
runtimeApi.cookies.get(cleanDetails, (cookie) => {
|
||||
const lastError = runtimeApi.runtime.lastError;
|
||||
|
||||
if (lastError) {
|
||||
reject(new Error(lastError.message));
|
||||
return;
|
||||
}
|
||||
|
||||
resolve(cookie);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function cookiesGetAllCookieStores() {
|
||||
if (!runtimeApi.cookies.getAllCookieStores) {
|
||||
return Promise.resolve([{ id: undefined }]);
|
||||
}
|
||||
|
||||
if (runtimeApi.cookies.getAllCookieStores.length === 0) {
|
||||
return runtimeApi.cookies.getAllCookieStores();
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
runtimeApi.cookies.getAllCookieStores((stores) => {
|
||||
const lastError = runtimeApi.runtime.lastError;
|
||||
|
||||
if (lastError) {
|
||||
reject(new Error(lastError.message));
|
||||
return;
|
||||
}
|
||||
|
||||
resolve(stores);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function removeUndefinedValues(details) {
|
||||
return Object.fromEntries(
|
||||
Object.entries(details).filter((entry) => entry[1] !== undefined)
|
||||
);
|
||||
}
|
||||
})();
|
||||
2345
dist/chromium/content.js
vendored
Normal file
2345
dist/chromium/content.js
vendored
Normal file
File diff suppressed because it is too large
Load Diff
28
dist/chromium/manifest.json
vendored
Normal file
28
dist/chromium/manifest.json
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"manifest_version": 3,
|
||||
"name": "Opportunities Extension",
|
||||
"description": "Adiciona um atalho de Opportunities Extension nas paginas Oracle Fusion permitidas.",
|
||||
"version": "0.1.0",
|
||||
"permissions": [
|
||||
"cookies"
|
||||
],
|
||||
"host_permissions": [
|
||||
"https://eeho.fa.us2.oraclecloud.com/*"
|
||||
],
|
||||
"content_scripts": [
|
||||
{
|
||||
"matches": [
|
||||
"https://eeho.fa.us2.oraclecloud.com/hcmUI/faces/FuseWelcome*",
|
||||
"https://eeho.fa.us2.oraclecloud.com/fscmUI/faces/FuseWelcome*"
|
||||
],
|
||||
"js": [
|
||||
"content.js"
|
||||
],
|
||||
"all_frames": true,
|
||||
"run_at": "document_idle"
|
||||
}
|
||||
],
|
||||
"background": {
|
||||
"service_worker": "background.js"
|
||||
}
|
||||
}
|
||||
216
dist/firefox/background.js
vendored
Normal file
216
dist/firefox/background.js
vendored
Normal file
@@ -0,0 +1,216 @@
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
const ORACLE_DOMAIN = "eeho.fa.us2.oraclecloud.com";
|
||||
const ORACLE_COOKIE_URLS = [
|
||||
"https://eeho.fa.us2.oraclecloud.com/",
|
||||
"https://eeho.fa.us2.oraclecloud.com/hcmUI/faces/FuseWelcome",
|
||||
"https://eeho.fa.us2.oraclecloud.com/fscmUI/faces/FuseWelcome",
|
||||
"https://eeho.fa.us2.oraclecloud.com/fscmRestApi/tokenrelay"
|
||||
];
|
||||
const XSRF_COOKIE_NAME = "XSRF-TOKEN-US2DZ2V_F";
|
||||
const XSRF_COOKIE_PREFIX = "XSRF-TOKEN-";
|
||||
const runtimeApi = typeof browser !== "undefined" ? browser : chrome;
|
||||
|
||||
runtimeApi.runtime.onMessage.addListener((message, sender, sendResponse) => {
|
||||
if (!message || message.type !== "opportunitiesExtension.getXsrfToken") {
|
||||
return false;
|
||||
}
|
||||
|
||||
getXsrfTokenCookie()
|
||||
.then((result) => {
|
||||
sendResponse({
|
||||
ok: true,
|
||||
cookieName: result.cookie ? result.cookie.name : "",
|
||||
token: result.cookie ? result.cookie.value : "",
|
||||
matchedCookieNames: result.matchedCookieNames,
|
||||
lookupDetails: result.lookupDetails
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
sendResponse({
|
||||
ok: false,
|
||||
cookieName: "",
|
||||
token: "",
|
||||
matchedCookieNames: [],
|
||||
lookupDetails: [],
|
||||
error: error.message || "Unable to read cookies."
|
||||
});
|
||||
});
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
async function getXsrfTokenCookie() {
|
||||
const lookupDetails = [];
|
||||
const allCookies = [];
|
||||
const stores = await getCookieStores(lookupDetails);
|
||||
|
||||
for (const store of stores) {
|
||||
const exactCookie = await getExactCookieFromUrls(store.id, lookupDetails);
|
||||
|
||||
if (exactCookie) {
|
||||
allCookies.push(exactCookie);
|
||||
}
|
||||
}
|
||||
|
||||
for (const store of stores) {
|
||||
await collectCookies({
|
||||
name: XSRF_COOKIE_NAME,
|
||||
storeId: store.id
|
||||
}, allCookies, lookupDetails);
|
||||
}
|
||||
|
||||
for (const store of stores) {
|
||||
await collectCookies({
|
||||
domain: ORACLE_DOMAIN,
|
||||
storeId: store.id
|
||||
}, allCookies, lookupDetails);
|
||||
|
||||
await collectCookies({
|
||||
domain: `.${ORACLE_DOMAIN}`,
|
||||
storeId: store.id
|
||||
}, allCookies, lookupDetails);
|
||||
}
|
||||
|
||||
for (const store of stores) {
|
||||
for (const url of ORACLE_COOKIE_URLS) {
|
||||
await collectCookies({
|
||||
url,
|
||||
storeId: store.id
|
||||
}, allCookies, lookupDetails);
|
||||
}
|
||||
}
|
||||
|
||||
const uniqueCookies = dedupeCookies(allCookies);
|
||||
const xsrfCookies = uniqueCookies.filter((cookie) => cookie.name.startsWith(XSRF_COOKIE_PREFIX));
|
||||
const exactCookie = xsrfCookies.find((cookie) => cookie.name === XSRF_COOKIE_NAME);
|
||||
const hostCookie = xsrfCookies.find((cookie) => cookie.domain === ORACLE_DOMAIN || cookie.domain === `.${ORACLE_DOMAIN}`);
|
||||
|
||||
return {
|
||||
cookie: exactCookie || hostCookie || xsrfCookies[0] || null,
|
||||
matchedCookieNames: xsrfCookies.map((cookie) => `${cookie.name} (${cookie.domain}${cookie.path})`),
|
||||
lookupDetails
|
||||
};
|
||||
}
|
||||
|
||||
async function getExactCookieFromUrls(storeId, lookupDetails) {
|
||||
for (const url of ORACLE_COOKIE_URLS) {
|
||||
const cookie = await cookiesGet({
|
||||
url,
|
||||
name: XSRF_COOKIE_NAME,
|
||||
storeId
|
||||
});
|
||||
|
||||
lookupDetails.push(`${JSON.stringify({ url, name: XSRF_COOKIE_NAME, storeId })} => ${cookie ? "found" : "not found"}`);
|
||||
|
||||
if (cookie) {
|
||||
return cookie;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
async function getCookieStores(lookupDetails) {
|
||||
try {
|
||||
const stores = await cookiesGetAllCookieStores();
|
||||
lookupDetails.push(`getAllCookieStores => ${stores.length} store(s)`);
|
||||
return stores.length ? stores : [{ id: undefined }];
|
||||
} catch (error) {
|
||||
lookupDetails.push(`getAllCookieStores => unavailable (${error.message || "unknown error"})`);
|
||||
return [{ id: undefined }];
|
||||
}
|
||||
}
|
||||
|
||||
async function collectCookies(details, target, lookupDetails) {
|
||||
const cleanDetails = removeUndefinedValues(details);
|
||||
const cookies = await cookiesGetAll(cleanDetails);
|
||||
target.push(...cookies);
|
||||
lookupDetails.push(`${JSON.stringify(cleanDetails)} => ${cookies.length} cookie(s)`);
|
||||
}
|
||||
|
||||
function dedupeCookies(cookies) {
|
||||
const seen = new Set();
|
||||
|
||||
return cookies.filter((cookie) => {
|
||||
const key = `${cookie.name}|${cookie.domain}|${cookie.path}|${cookie.storeId || ""}`;
|
||||
|
||||
if (seen.has(key)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
seen.add(key);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
function cookiesGetAll(details) {
|
||||
if (runtimeApi.cookies.getAll.length <= 1) {
|
||||
return runtimeApi.cookies.getAll(details);
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
runtimeApi.cookies.getAll(details, (cookies) => {
|
||||
const lastError = runtimeApi.runtime.lastError;
|
||||
|
||||
if (lastError) {
|
||||
reject(new Error(lastError.message));
|
||||
return;
|
||||
}
|
||||
|
||||
resolve(cookies);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function cookiesGet(details) {
|
||||
const cleanDetails = removeUndefinedValues(details);
|
||||
|
||||
if (runtimeApi.cookies.get.length <= 1) {
|
||||
return runtimeApi.cookies.get(cleanDetails);
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
runtimeApi.cookies.get(cleanDetails, (cookie) => {
|
||||
const lastError = runtimeApi.runtime.lastError;
|
||||
|
||||
if (lastError) {
|
||||
reject(new Error(lastError.message));
|
||||
return;
|
||||
}
|
||||
|
||||
resolve(cookie);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function cookiesGetAllCookieStores() {
|
||||
if (!runtimeApi.cookies.getAllCookieStores) {
|
||||
return Promise.resolve([{ id: undefined }]);
|
||||
}
|
||||
|
||||
if (runtimeApi.cookies.getAllCookieStores.length === 0) {
|
||||
return runtimeApi.cookies.getAllCookieStores();
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
runtimeApi.cookies.getAllCookieStores((stores) => {
|
||||
const lastError = runtimeApi.runtime.lastError;
|
||||
|
||||
if (lastError) {
|
||||
reject(new Error(lastError.message));
|
||||
return;
|
||||
}
|
||||
|
||||
resolve(stores);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function removeUndefinedValues(details) {
|
||||
return Object.fromEntries(
|
||||
Object.entries(details).filter((entry) => entry[1] !== undefined)
|
||||
);
|
||||
}
|
||||
})();
|
||||
2345
dist/firefox/content.js
vendored
Normal file
2345
dist/firefox/content.js
vendored
Normal file
File diff suppressed because it is too large
Load Diff
35
dist/firefox/manifest.json
vendored
Normal file
35
dist/firefox/manifest.json
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"manifest_version": 3,
|
||||
"name": "Opportunities Extension",
|
||||
"description": "Adiciona um atalho de Opportunities Extension nas paginas Oracle Fusion permitidas.",
|
||||
"version": "0.1.0",
|
||||
"permissions": [
|
||||
"cookies"
|
||||
],
|
||||
"host_permissions": [
|
||||
"https://eeho.fa.us2.oraclecloud.com/*"
|
||||
],
|
||||
"content_scripts": [
|
||||
{
|
||||
"matches": [
|
||||
"https://eeho.fa.us2.oraclecloud.com/hcmUI/faces/FuseWelcome*",
|
||||
"https://eeho.fa.us2.oraclecloud.com/fscmUI/faces/FuseWelcome*"
|
||||
],
|
||||
"js": [
|
||||
"content.js"
|
||||
],
|
||||
"all_frames": true,
|
||||
"run_at": "document_idle"
|
||||
}
|
||||
],
|
||||
"background": {
|
||||
"scripts": [
|
||||
"background.js"
|
||||
]
|
||||
},
|
||||
"browser_specific_settings": {
|
||||
"gecko": {
|
||||
"id": "opportunities-extension@local.dev"
|
||||
}
|
||||
}
|
||||
}
|
||||
10
package.json
Normal file
10
package.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"name": "opportunities-extension",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"build": "node scripts/build.mjs",
|
||||
"check": "node --check src/content.js && node scripts/build.mjs --check"
|
||||
}
|
||||
}
|
||||
85
scripts/build.mjs
Normal file
85
scripts/build.mjs
Normal file
@@ -0,0 +1,85 @@
|
||||
import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
const rootDir = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
|
||||
const srcDir = path.join(rootDir, "src");
|
||||
const distDir = path.join(rootDir, "dist");
|
||||
const contentScript = await readFile(path.join(srcDir, "content.js"), "utf8");
|
||||
const backgroundScript = await readFile(path.join(srcDir, "background.js"), "utf8");
|
||||
const checkOnly = process.argv.includes("--check");
|
||||
|
||||
const baseManifest = {
|
||||
manifest_version: 3,
|
||||
name: "Opportunities Extension",
|
||||
description: "Adiciona um atalho de Opportunities Extension nas paginas Oracle Fusion permitidas.",
|
||||
version: "0.1.0",
|
||||
permissions: [
|
||||
"cookies"
|
||||
],
|
||||
host_permissions: [
|
||||
"https://eeho.fa.us2.oraclecloud.com/*"
|
||||
],
|
||||
content_scripts: [
|
||||
{
|
||||
matches: [
|
||||
"https://eeho.fa.us2.oraclecloud.com/hcmUI/faces/FuseWelcome*",
|
||||
"https://eeho.fa.us2.oraclecloud.com/fscmUI/faces/FuseWelcome*"
|
||||
],
|
||||
js: ["content.js"],
|
||||
all_frames: true,
|
||||
run_at: "document_idle"
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
const targets = [
|
||||
{
|
||||
name: "chromium",
|
||||
manifest: {
|
||||
...baseManifest,
|
||||
background: {
|
||||
service_worker: "background.js"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
name: "firefox",
|
||||
manifest: {
|
||||
...baseManifest,
|
||||
background: {
|
||||
scripts: ["background.js"]
|
||||
},
|
||||
browser_specific_settings: {
|
||||
gecko: {
|
||||
id: "opportunities-extension@local.dev"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
if (!checkOnly) {
|
||||
await rm(distDir, { recursive: true, force: true });
|
||||
}
|
||||
|
||||
for (const target of targets) {
|
||||
const manifestJson = `${JSON.stringify(target.manifest, null, 2)}\n`;
|
||||
JSON.parse(manifestJson);
|
||||
|
||||
if (checkOnly) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const outputDir = path.join(distDir, target.name);
|
||||
await mkdir(outputDir, { recursive: true });
|
||||
await writeFile(path.join(outputDir, "manifest.json"), manifestJson);
|
||||
await writeFile(path.join(outputDir, "content.js"), contentScript);
|
||||
await writeFile(path.join(outputDir, "background.js"), backgroundScript);
|
||||
}
|
||||
|
||||
if (!checkOnly) {
|
||||
console.log("Build gerado em dist/chromium e dist/firefox.");
|
||||
} else {
|
||||
console.log("Build check ok.");
|
||||
}
|
||||
216
src/background.js
Normal file
216
src/background.js
Normal file
@@ -0,0 +1,216 @@
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
const ORACLE_DOMAIN = "eeho.fa.us2.oraclecloud.com";
|
||||
const ORACLE_COOKIE_URLS = [
|
||||
"https://eeho.fa.us2.oraclecloud.com/",
|
||||
"https://eeho.fa.us2.oraclecloud.com/hcmUI/faces/FuseWelcome",
|
||||
"https://eeho.fa.us2.oraclecloud.com/fscmUI/faces/FuseWelcome",
|
||||
"https://eeho.fa.us2.oraclecloud.com/fscmRestApi/tokenrelay"
|
||||
];
|
||||
const XSRF_COOKIE_NAME = "XSRF-TOKEN-US2DZ2V_F";
|
||||
const XSRF_COOKIE_PREFIX = "XSRF-TOKEN-";
|
||||
const runtimeApi = typeof browser !== "undefined" ? browser : chrome;
|
||||
|
||||
runtimeApi.runtime.onMessage.addListener((message, sender, sendResponse) => {
|
||||
if (!message || message.type !== "opportunitiesExtension.getXsrfToken") {
|
||||
return false;
|
||||
}
|
||||
|
||||
getXsrfTokenCookie()
|
||||
.then((result) => {
|
||||
sendResponse({
|
||||
ok: true,
|
||||
cookieName: result.cookie ? result.cookie.name : "",
|
||||
token: result.cookie ? result.cookie.value : "",
|
||||
matchedCookieNames: result.matchedCookieNames,
|
||||
lookupDetails: result.lookupDetails
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
sendResponse({
|
||||
ok: false,
|
||||
cookieName: "",
|
||||
token: "",
|
||||
matchedCookieNames: [],
|
||||
lookupDetails: [],
|
||||
error: error.message || "Unable to read cookies."
|
||||
});
|
||||
});
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
async function getXsrfTokenCookie() {
|
||||
const lookupDetails = [];
|
||||
const allCookies = [];
|
||||
const stores = await getCookieStores(lookupDetails);
|
||||
|
||||
for (const store of stores) {
|
||||
const exactCookie = await getExactCookieFromUrls(store.id, lookupDetails);
|
||||
|
||||
if (exactCookie) {
|
||||
allCookies.push(exactCookie);
|
||||
}
|
||||
}
|
||||
|
||||
for (const store of stores) {
|
||||
await collectCookies({
|
||||
name: XSRF_COOKIE_NAME,
|
||||
storeId: store.id
|
||||
}, allCookies, lookupDetails);
|
||||
}
|
||||
|
||||
for (const store of stores) {
|
||||
await collectCookies({
|
||||
domain: ORACLE_DOMAIN,
|
||||
storeId: store.id
|
||||
}, allCookies, lookupDetails);
|
||||
|
||||
await collectCookies({
|
||||
domain: `.${ORACLE_DOMAIN}`,
|
||||
storeId: store.id
|
||||
}, allCookies, lookupDetails);
|
||||
}
|
||||
|
||||
for (const store of stores) {
|
||||
for (const url of ORACLE_COOKIE_URLS) {
|
||||
await collectCookies({
|
||||
url,
|
||||
storeId: store.id
|
||||
}, allCookies, lookupDetails);
|
||||
}
|
||||
}
|
||||
|
||||
const uniqueCookies = dedupeCookies(allCookies);
|
||||
const xsrfCookies = uniqueCookies.filter((cookie) => cookie.name.startsWith(XSRF_COOKIE_PREFIX));
|
||||
const exactCookie = xsrfCookies.find((cookie) => cookie.name === XSRF_COOKIE_NAME);
|
||||
const hostCookie = xsrfCookies.find((cookie) => cookie.domain === ORACLE_DOMAIN || cookie.domain === `.${ORACLE_DOMAIN}`);
|
||||
|
||||
return {
|
||||
cookie: exactCookie || hostCookie || xsrfCookies[0] || null,
|
||||
matchedCookieNames: xsrfCookies.map((cookie) => `${cookie.name} (${cookie.domain}${cookie.path})`),
|
||||
lookupDetails
|
||||
};
|
||||
}
|
||||
|
||||
async function getExactCookieFromUrls(storeId, lookupDetails) {
|
||||
for (const url of ORACLE_COOKIE_URLS) {
|
||||
const cookie = await cookiesGet({
|
||||
url,
|
||||
name: XSRF_COOKIE_NAME,
|
||||
storeId
|
||||
});
|
||||
|
||||
lookupDetails.push(`${JSON.stringify({ url, name: XSRF_COOKIE_NAME, storeId })} => ${cookie ? "found" : "not found"}`);
|
||||
|
||||
if (cookie) {
|
||||
return cookie;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
async function getCookieStores(lookupDetails) {
|
||||
try {
|
||||
const stores = await cookiesGetAllCookieStores();
|
||||
lookupDetails.push(`getAllCookieStores => ${stores.length} store(s)`);
|
||||
return stores.length ? stores : [{ id: undefined }];
|
||||
} catch (error) {
|
||||
lookupDetails.push(`getAllCookieStores => unavailable (${error.message || "unknown error"})`);
|
||||
return [{ id: undefined }];
|
||||
}
|
||||
}
|
||||
|
||||
async function collectCookies(details, target, lookupDetails) {
|
||||
const cleanDetails = removeUndefinedValues(details);
|
||||
const cookies = await cookiesGetAll(cleanDetails);
|
||||
target.push(...cookies);
|
||||
lookupDetails.push(`${JSON.stringify(cleanDetails)} => ${cookies.length} cookie(s)`);
|
||||
}
|
||||
|
||||
function dedupeCookies(cookies) {
|
||||
const seen = new Set();
|
||||
|
||||
return cookies.filter((cookie) => {
|
||||
const key = `${cookie.name}|${cookie.domain}|${cookie.path}|${cookie.storeId || ""}`;
|
||||
|
||||
if (seen.has(key)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
seen.add(key);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
function cookiesGetAll(details) {
|
||||
if (runtimeApi.cookies.getAll.length <= 1) {
|
||||
return runtimeApi.cookies.getAll(details);
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
runtimeApi.cookies.getAll(details, (cookies) => {
|
||||
const lastError = runtimeApi.runtime.lastError;
|
||||
|
||||
if (lastError) {
|
||||
reject(new Error(lastError.message));
|
||||
return;
|
||||
}
|
||||
|
||||
resolve(cookies);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function cookiesGet(details) {
|
||||
const cleanDetails = removeUndefinedValues(details);
|
||||
|
||||
if (runtimeApi.cookies.get.length <= 1) {
|
||||
return runtimeApi.cookies.get(cleanDetails);
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
runtimeApi.cookies.get(cleanDetails, (cookie) => {
|
||||
const lastError = runtimeApi.runtime.lastError;
|
||||
|
||||
if (lastError) {
|
||||
reject(new Error(lastError.message));
|
||||
return;
|
||||
}
|
||||
|
||||
resolve(cookie);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function cookiesGetAllCookieStores() {
|
||||
if (!runtimeApi.cookies.getAllCookieStores) {
|
||||
return Promise.resolve([{ id: undefined }]);
|
||||
}
|
||||
|
||||
if (runtimeApi.cookies.getAllCookieStores.length === 0) {
|
||||
return runtimeApi.cookies.getAllCookieStores();
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
runtimeApi.cookies.getAllCookieStores((stores) => {
|
||||
const lastError = runtimeApi.runtime.lastError;
|
||||
|
||||
if (lastError) {
|
||||
reject(new Error(lastError.message));
|
||||
return;
|
||||
}
|
||||
|
||||
resolve(stores);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function removeUndefinedValues(details) {
|
||||
return Object.fromEntries(
|
||||
Object.entries(details).filter((entry) => entry[1] !== undefined)
|
||||
);
|
||||
}
|
||||
})();
|
||||
2345
src/content.js
Normal file
2345
src/content.js
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user