Skip to content

Commit

Permalink
v1.28.18
Browse files Browse the repository at this point in the history
  • Loading branch information
Kholid060 committed Oct 30, 2023
2 parents 0457860 + e9105f6 commit e9810b3
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 23 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "automa",
"version": "1.28.17",
"version": "1.28.18",
"description": "An extension for automating your browser by connecting blocks",
"repository": {
"type": "git",
Expand Down
35 changes: 35 additions & 0 deletions src/background/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,4 +253,39 @@ if (!isMV2) {
sandboxIframe.id = 'sandbox';

document.body.appendChild(sandboxIframe);

window.addEventListener('message', async ({ data }) => {
if (data?.type !== 'automa-fetch') return;

const sendResponse = (result) => {
sandboxIframe.contentWindow.postMessage(
{
type: 'fetchResponse',
data: result,
id: data.data.id,
},
'*'
);
};

const { type, resource } = data.data;
try {
const response = await fetch(resource.url, resource);
if (!response.ok) throw new Error(response.statusText);

let result = null;

if (type === 'base64') {
const blob = await response.blob();
const base64 = await readFileAsBase64(blob);

result = base64;
} else {
result = await response[type]();
}
sendResponse({ isError: false, result });
} catch (error) {
sendResponse({ isError: true, result: error.message });
}
});
}
2 changes: 1 addition & 1 deletion src/components/newtab/workflow/edit/EditJavascriptCode.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
Run before page loaded
</ui-checkbox>
</template>
<ui-modal v-model="state.showCodeModal" content-class="max-w-4xl">
<ui-modal v-model="state.showCodeModal" content-class="w-11\/12">
<template #header>
<ui-tabs v-model="state.activeTab" class="border-none">
<ui-tab value="code">
Expand Down
14 changes: 10 additions & 4 deletions src/content/handleSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@ export function markElement(el, { id, data }) {
}

export function getDocumentCtx(frameSelector) {
if (!frameSelector) return document;

let documentCtx = document;

if (frameSelector) {
const type = isXPath(frameSelector) ? 'xpath' : 'cssSelector';
const element = FindElement[type]({ selector: frameSelector });
const iframeSelectors = frameSelector.split('|>');
const type = isXPath(frameSelector) ? 'xpath' : 'cssSelector';
iframeSelectors.forEach((selector) => {
if (!documentCtx) return;

const element = FindElement[type]({ selector }, documentCtx);
documentCtx = element?.contentDocument;
}
});

return documentCtx;
}
Expand Down Expand Up @@ -62,6 +67,7 @@ export default async function (
}

const documentCtx = getDocumentCtx(frameSelector);

if (!documentCtx) {
if (onError) onError(new Error('iframe-not-found'));

Expand Down
27 changes: 19 additions & 8 deletions src/content/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import findSelector from '@/lib/findSelector';
import { sendMessage } from '@/utils/message';
import automa from '@business';
import { toCamelCase, isXPath } from '@/utils/helper';
import handleSelector, { queryElements } from './handleSelector';
import handleSelector, {
queryElements,
getDocumentCtx,
} from './handleSelector';
import blocksHandler from './blocksHandler';
import showExecutedBlock from './showExecutedBlock';
import shortcutListener from './services/shortcutListener';
Expand Down Expand Up @@ -49,19 +52,27 @@ function messageToFrame(frameElement, blockData) {
async function executeBlock(data) {
const removeExecutedBlock = showExecutedBlock(data, data.executedBlockOnWeb);
if (data.data?.selector?.includes('|>')) {
const [frameSelector, selector] = data.data.selector.split(/\|>(.+)/);
const selectorsArr = data.data.selector.split('|>');
const selector = selectorsArr.pop();
const frameSelector = selectorsArr.join('|>');

const framElSelector = selectorsArr.pop();

let findBy = data?.data?.findBy;
if (!findBy) {
findBy = isXPath(frameSelector) ? 'xpath' : 'cssSelector';
}

const frameElement = await queryElements({
findBy,
multiple: false,
waitForSelector: 5000,
selector: frameSelector,
});
const documentCtx = getDocumentCtx(selectorsArr.join('|>'));
const frameElement = await queryElements(
{
findBy,
multiple: false,
waitForSelector: 5000,
selector: framElSelector,
},
documentCtx
);
const frameError = (message) => {
const error = new Error(message);
error.data = { selector: frameSelector };
Expand Down
12 changes: 7 additions & 5 deletions src/newtab/pages/workflows/[id].vue
Original file line number Diff line number Diff line change
Expand Up @@ -1239,12 +1239,15 @@ function onDragoverEditor({ target }) {
}
function onDropInEditor({ dataTransfer, clientX, clientY, target }) {
const savedBlocks = parseJSON(dataTransfer.getData('savedBlocks'), null);
const editorRect = editor.value.viewportRef.value.getBoundingClientRect();
const position = editor.value.project({
y: clientY - editorRect.top,
x: clientX - editorRect.left,
});
if (savedBlocks && !isPackage) {
if (savedBlocks.settings.asBlock) {
const position = editor.value.project({
x: clientX - 360,
y: clientY - 18,
});
editor.value.addNodes([
{
position,
Expand Down Expand Up @@ -1285,7 +1288,6 @@ function onDropInEditor({ dataTransfer, clientX, clientY, target }) {
return;
}
const position = editor.value.project({ x: clientX - 360, y: clientY - 18 });
const nodeId = nanoid();
const newNode = {
position,
Expand Down
9 changes: 5 additions & 4 deletions src/workflowEngine/blocksHandler/handlerHandleDownload.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,16 @@ async function handleDownload({ data, id: blockId }) {
return;
}

if (downloadId !== id) return;
if (downloadId !== id || !state) return;

if (filename) currentFilename = filename.current;

if (state && state.current === 'complete') {
const DOWNLOAD_STATE = ['complete', 'interrupted'];
if (DOWNLOAD_STATE.includes(state.current)) {
resolvePromise(id);
} else {
browser.downloads.search({ id }).then(([download]) => {
if (!download || !download.endTime) return;
browser.downloads.search({ id: downloadId }).then(([download]) => {
if (!download || !DOWNLOAD_STATE.includes(download.state)) return;

resolvePromise(id);
});
Expand Down

0 comments on commit e9810b3

Please sign in to comment.