Browse Source

fix: can't take a screenshot of an element

Ahmad Kholid 3 years ago
parent
commit
8c5e3e35c7

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
   "name": "automa",
-  "version": "1.11.0",
+  "version": "1.11.1",
   "description": "An extension for automating your browser by connecting blocks",
   "license": "MIT",
   "repository": {

+ 4 - 2
src/background/workflowEngine/blocksHandler/handlerTakeScreenshot.js

@@ -87,8 +87,10 @@ async function takeScreenshot({ data, outputs, name }) {
         ? this._sendMessageToTab({
             name,
             options,
-            type: data.type,
-            selector: data.selector,
+            data: {
+              type: data.type,
+              selector: data.selector,
+            },
             tabId: this.activeTab.id,
           })
         : captureTab());

+ 2 - 2
src/content/blocksHandler/handlerJavascriptCode.js

@@ -56,8 +56,8 @@ function javascriptCode(block) {
     const promisePreloadScripts =
       block.data?.preloadScripts?.map(async (item) => {
         try {
-          const { protocol, pathname } = new URL(item.src);
-          const isValidUrl = /https?/.test(protocol) && /\.js$/.test(pathname);
+          const { protocol } = new URL(item.src);
+          const isValidUrl = /https?/.test(protocol);
 
           if (!isValidUrl) return null;
 

+ 1 - 1
src/content/blocksHandler/handlerTakeScreenshot.js

@@ -90,7 +90,7 @@ async function captureElementScreenshot({ selector, tabId, options }) {
   return canvasToBase64(canvas, options);
 }
 
-export default async function ({ tabId, options, type, selector }) {
+export default async function ({ tabId, options, data: { type, selector } }) {
   if (type === 'element') {
     const imageUrl = await captureElementScreenshot({
       tabId,

+ 1 - 1
src/content/index.js

@@ -37,7 +37,7 @@ function messageToFrame(frameElement, blockData) {
 async function executeBlock(data) {
   const removeExecutedBlock = showExecutedBlock(data, data.executedBlockOnWeb);
 
-  if (data.data.selector?.includes('|>') && isMainFrame) {
+  if (data.data?.selector?.includes('|>') && isMainFrame) {
     const [frameSelector, selector] = data.data.selector.split(/\|>(.+)/);
     const frameElement = document.querySelector(frameSelector);
     const frameError = (message) => {

+ 1 - 1
src/newtab/App.vue

@@ -23,7 +23,7 @@
       </template>
     </ui-dialog>
     <div
-      v-if="isUpdated"
+      v-if="false"
       class="p-4 shadow-2xl z-50 fixed bottom-8 left-1/2 -translate-x-1/2 rounded-lg bg-accent text-white dark:text-gray-900 flex items-center"
     >
       <v-remixicon name="riInformationLine" class="mr-3" />