Chrome Extension won't run on pages with "redirect to external app" popup

153 views
Skip to first unread message

Eli Eliashar

unread,
Mar 8, 2022, 10:02:42 AM3/8/22
to Chromium Extensions
Hi,
We are facing an issue with our Chrome Extension: The chrome extension content script, won't run on web pages which, on load, show a small popup asking the user the permission to open the page in an external app. For example, when viewing this page:
The user is immediately asked to open the page in the App Store. In this case, the extension is not run at all, even though it would have been without this popup. Any help would be appreciated.

Thanks

Cuyler Stuwe

unread,
Mar 8, 2022, 11:20:21 AM3/8/22
to Eli Eliashar, Chromium Extensions
I would assume this is totally by design and that there’s little you can do about it directly on that page.

Seems to me that your only option would probably be to redirect requests to those pages to an intermediate page. Not sure how feasible this would be in an MV3 extension at this point.

--
You received this message because you are subscribed to the Google Groups "Chromium Extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/01fdb804-db98-4eec-aa22-93f341b298c9n%40chromium.org.

Stefan vd

unread,
Mar 8, 2022, 3:08:13 PM3/8/22
to Chromium Extensions, salem...@gmail.com, Chromium Extensions, elia...@gmail.com
Hi everyone,

@Elia
I try your research your issue with my Chrome extension MV2 that uses a content script (add automatically a Night switch on the current web page <= to get dark mode). In doing so, I can see the same problem you describe here, the Apple pop-up message appearing to open the third-party application. And that it doesn't run and puts the custom HTML code on the Apple App Store page.
However, when I try my Chrome extension MV3, I see no problem. It puts my custom night switch (bottom left) as you can see in my screenshot in this post.
Screenshot 2022-03-08 at 21.00.20.png

Chrome Dev Version 101.0.4919.0 on a Chrome extension manifest v3.

Have you tried converting your Chrome extension to manifest v3?

Thanks,
Stefan vd

Eli Eliashar

unread,
Mar 9, 2022, 3:04:44 AM3/9/22
to Stefan vd, Chromium Extensions, salem...@gmail.com
Thanks all. I'll try to upgrade to MV3. I'm still using the 2 for certain reasons.

Simeon Vincent

unread,
Mar 9, 2022, 3:13:12 PM3/9/22
to Eli Eliashar, Stefan vd, Chromium Extensions, salem...@gmail.com
Just did a little testing and it looks like my minimal MV2 behaves as expected. It might be worth digging more into where exactly your extensions is going off the rails.

manifest.json
{
"name": "Content scripts - inject on all pages",
"version": "1.0",
"manifest_version": 2,
"content_scripts": [
{
"matches": ["https://apps.apple.com/*"],
"js": ["content.js"],
"run_at": "document_start"
}
]
}

background.js
console.log('injecting a red square');

let el = document.createElement('div');
el.style.height = "100px";
el.style.position = "fixed";
el.style.width = "100px";
el.style.top = "0";
el.style.left = "0";
el.style.margin = "0";
el.style.padding = "0";
el.style.background = "red";

// document.body does not exist at this point
document.documentElement.append(el);

console.log('injected element', el);

Simeon - @dotproto
Chrome Extensions DevRel


Eli Eliashar

unread,
Mar 10, 2022, 4:14:37 AM3/10/22
to Simeon Vincent, Stefan vd, Chromium Extensions, salem...@gmail.com
Hi Simeon,

The background runs well but the content script does not unfortunately.

Eli Eliashar

unread,
Mar 21, 2022, 5:59:00 AM3/21/22
to Simeon Vincent, Stefan vd, Chromium Extensions, salem...@gmail.com
After upgrading to MV3 I still experience this issue. Anyone managed to solve this? Is there any workaround?

Stefan vd

unread,
Mar 21, 2022, 6:06:21 AM3/21/22
to Chromium Extensions, elia...@gmail.com, Stefan vd, Chromium Extensions, salem...@gmail.com, Simeon Vincent
Hi Elia,

I can not confirm this issue in my manifest v3 Chrome extension, and Simeon can also not simulate this issue in manifest v2.
Could you share your code on Github (a simplistic version of your Chrome extension)? That will help us simulate this issue on our Chrome web browser.

Thanks,
Stefan vd

Message has been deleted

Eli Eliashar

unread,
Mar 21, 2022, 6:13:51 AM3/21/22
to Chromium Extensions, Stefan vd, salem...@gmail.com, Simeon Vincent
Hi,
So Simon was able to run his extension as his code was run by the background script and not by a content script.
Regarding you being able to run your extension with MV3 - can you please post your manifest file? Maybe I am missing something. 
Otherwise, I can crearte a mini version of my extension but it will take me some time as it is a large complicated extension with some confidencial parts.

Thanks again!

On Mon, Mar 21, 2022 at 12:12 PM Ilay Eliashar <il...@storemaven.com> wrote:
Hi,
So Simon was able to run his extension as his code was run by the background script and not by a content script.
Regarding you being able to run your extension with MV3 - can you please post your manifest file? Maybe I am missing something. 
Otherwise, I can crearte a mini version of my extension but it will take me some time as it is a large complicated extension with some confidencial parts.

Thanks again!

Stefan vd

unread,
Mar 21, 2022, 6:56:18 AM3/21/22
to Chromium Extensions, elia...@gmail.com, Chromium Extensions, Stefan vd, salem...@gmail.com, Simeon Vincent
Hi Elia,

I think that @Simeon did just a typo, "background.js" => is really "content.js" in his code sample.

Here is my manifest v3 code.

manifest.json
{
"name": "Test extenstion",
"description": "Test Extension!",
"version": "1.0",
"manifest_version": 3,
"background": {
"service_worker": "background.js"
},
"content_scripts": [
{
"matches": ["https://apps.apple.com/*"],
"js": ["content.js"],
"run_at": "document_start",
"all_frames": true
},
{
"matches": ["https://apps.apple.com/*"],
"css" : ["style.css"]
}
],
"action": {},
"permissions": ["storage", "activeTab", "scripting"],
"minimum_chrome_version": "99"
}

background.js
chrome.action.onClicked.addListener((tab) => {
chrome.scripting.executeScript({
target: {tabId: tab.id},
files: ['script.js']
});
});

script.js
alert("done run script");

content.js
console.log("Start content injection");
if(document.documentElement){
var newswitch = document.createElement("div");
newswitch.id = "stefanswitch"
newswitch.className = "stefanswitch";
document.documentElement.append(newswitch);
}
console.log("End content injection");

style.css
.stefanswitch{z-index:100000;position:absolute;top:0;left:0;width:200px;height:200px;background:red}

Thanks,
Stefan vd

Eli Eliashar

unread,
Mar 21, 2022, 7:39:14 AM3/21/22
to Stefan vd, Chromium Extensions, salem...@gmail.com, Simeon Vincent
Ok - solved it:
Seems like the "run_at" field is a game changer here. The default value is "document_end" - but then nothing would run. Once I changed it to "document_start", the content script is running before the popup that is shown to the user.

Thanks :)

Stefan vd

unread,
Mar 21, 2022, 7:44:07 AM3/21/22
to Chromium Extensions, elia...@gmail.com, Chromium Extensions, salem...@gmail.com, Simeon Vincent, Stefan vd
Hi Elia,

I am glad you solved your problem.
Have a nice Chromie day there.

Thanks,
Stefan vd

Tarun Khandelwal

unread,
Aug 12, 2022, 3:07:42 AM8/12/22
to Chromium Extensions, Stefan vd, elia...@gmail.com, Chromium Extensions, salem...@gmail.com, Simeon Vincent
Hi, 

I am also facing the same issue, but I can't run the app on "document_start" as my extension depends on the content of the webpage so is there any other solution this ?

hrg...@gmail.com

unread,
Aug 12, 2022, 5:58:48 PM8/12/22
to Chromium Extensions, ta...@gkmit.co, Stefan vd, elia...@gmail.com, Chromium Extensions, salem...@gmail.com, Simeon Vincent
Does your content script run if you click the "Cancel" button in that dialog box?

Tarun Khandelwal

unread,
Aug 12, 2022, 10:41:35 PM8/12/22
to Chromium Extensions, hrg...@gmail.com, Tarun Khandelwal, Stefan vd, elia...@gmail.com, Chromium Extensions, salem...@gmail.com, Simeon Vincent
No it doesn't.

hrg...@gmail.com

unread,
Aug 12, 2022, 11:03:18 PM8/12/22
to Chromium Extensions, ta...@gkmit.co, hrg...@gmail.com, Stefan vd, elia...@gmail.com, Chromium Extensions, salem...@gmail.com, Simeon Vincent
Then you can inject the content script at document_start and add an event listener for the "load" event or the "DOMContentLoaded" event.
The webpage content that your script depends on should be available when one of those events fire.

Tarun Khandelwal

unread,
Aug 16, 2022, 7:30:56 AM8/16/22
to Chromium Extensions, hrg...@gmail.com, Tarun Khandelwal, Stefan vd, elia...@gmail.com, Chromium Extensions, salem...@gmail.com, Simeon Vincent
Thanks hrg for the help, the solution worked!
Reply all
Reply to author
Forward
0 new messages