From e678ff1bb09f2bc63ed3216222fd571a17cc8ee7 Mon Sep 17 00:00:00 2001 From: Chris Date: Sat, 27 Jan 2024 08:59:49 +0000 Subject: [PATCH] Gmail fix (#107) * Fix for replacing in gmail draft emails * Try to ignore other iframes * Accept iframes from same host or blobs * wip * wip related to occurrences * Fix faulty if condition for iframes * Sort out iframe selector * configure webpack --- manifest.json | 2 +- package.json | 2 +- src/constants.ts | 2 +- src/elements.ts | 29 ++++++++++--- src/searchreplace.ts | 100 +++++++++++++++++++++++-------------------- 5 files changed, 80 insertions(+), 55 deletions(-) diff --git a/manifest.json b/manifest.json index 30252fc..9416c1d 100644 --- a/manifest.json +++ b/manifest.json @@ -31,7 +31,7 @@ "permissions": ["activeTab", "storage", "notifications"], "host_permissions": ["http://*/*", "https://*/*"], "update_url": "http://clients2.google.com/service/update2/crx", - "version":"2.0.5", + "version":"2.0.6", "options_page": "assets/options.html", "icons": { "16": "assets/icon-16.png", diff --git a/package.json b/package.json index 9b4152e..c25fe2d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "search_and_replace", - "version": "2.0.5", + "version": "2.0.6", "resolutions": { "author": "Chris Taylor " }, diff --git a/src/constants.ts b/src/constants.ts index ded6223..d46ad54 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -4,7 +4,7 @@ export const ELEMENT_FILTER = /(HTML|HEAD|SCRIPT|STYLE|IFRAME)/i export const INPUT_TEXTAREA_FILTER = /(INPUT|TEXTAREA)/ export const HINTS: Record = { gmail: { - hint: 'Hint: Gmail detected. Check "Visible content only?" when editing draft emails.', + hint: 'Hint: Gmail detected. Check "Input fields only?" when editing draft emails.', domain: 'mail.google.com', selector: `meta[content="Gmail"]`, name: 'gmail', diff --git a/src/elements.ts b/src/elements.ts index 8fa20d9..3e625d7 100644 --- a/src/elements.ts +++ b/src/elements.ts @@ -1,5 +1,6 @@ // Utils for dealing with Elements +import { HINTS } from './constants' import { SearchReplaceResult } from './types' export function getInputElements( @@ -19,15 +20,33 @@ export function isBlobIframe(el: Element) { } export function getIframeElements(document: Document, blob = false): HTMLIFrameElement[] { - return Array.from(>document.querySelectorAll('iframe')).filter( - (iframe) => - // We don't want empty iframes - iframe.src.length && + // we don't want to count iframes in gmail + if (document.querySelector(HINTS['gmail'].selector) || window.location.href.indexOf(HINTS['gmail'].domain) > -1) { + return [] + } + + return Array.from(>document.querySelectorAll('iframe')).filter((iframe) => { + console.log('iframe.src.length', iframe.src.length) + console.log("iframe.src.startsWith('chrome-extension://')", iframe.src.startsWith('chrome-extension://')) + console.log('window location origin', window.location.origin) + console.log('iframe.src.startsWith(window.location.origin)', iframe.src.startsWith(window.location.origin)) + console.log('blob', blob) + console.log('isBlobIframe(iframe)', isBlobIframe(iframe)) + console.log( + '(blob ? isBlobIframe(iframe) : !isBlobIframe(iframe))', + blob ? isBlobIframe(iframe) : !isBlobIframe(iframe) + ) + // We don't want empty iframes + const want = + iframe.src.length > 0 && // We don't want to count iframes injected by other chrome extensions !iframe.src.startsWith('chrome-extension://') && + // We only want to wait on iframes from the same origin OR blob iframes + iframe.src.indexOf(window.location.origin) > -1 && // We may or may not want blob iframes (blob ? isBlobIframe(iframe) : !isBlobIframe(iframe)) - ) + return want + }) } export function inIframe() { diff --git a/src/searchreplace.ts b/src/searchreplace.ts index c44fb3c..c3a01bb 100644 --- a/src/searchreplace.ts +++ b/src/searchreplace.ts @@ -186,10 +186,11 @@ function containsAncestor(element: Element, results: Map