Inject Iframe

254 views
Skip to first unread message

Natan Rotta

unread,
Sep 22, 2022, 10:17:04 AM9/22/22
to Chromium Extensions
Hello guys. I need to inject an Iframe into the current tab. This Iframe should occupy about 30% of the screen in the right field. How can you do that?

Stefan vd

unread,
Oct 2, 2022, 3:07:17 PM10/2/22
to Chromium Extensions, na...@clint.digital
Hi there,

You can use this script code to place the iframe element in the current tab, for example:
Manifest V3 Chrome extension
run.js
        const newDiv = document.createElement("iframe");
        newDiv.src = "https://www.google.com";
        newDiv.style.width = "30%";
        newDiv.style.height = "100vh";
        newDiv.style.position = "absolute";
        newDiv.style.top = "0";
        newDiv.style.right = "0";
        newDiv.style.zIndex = "1000";
        newDiv.innerText = "Element";
        document.body.appendChild(newDiv);


background.js
        chrome.action.onClicked.addListener(function(tab){
        chrome.scripting.executeScript({
        target: {tabId: tab.id},
        files: ["js/run.js"]
        });
        });

Thanks,
Stefan vd

Natan Rotta

unread,
Oct 3, 2022, 8:11:06 AM10/3/22
to Chromium Extensions, stefa...@gmail.com, Natan Rotta
Hey, Stefan! Thanks!

I built a project model using the injection strategy.
This one uses React.js as a base.

 Follow my repository: https://github.com/natanrotta/react-chrome-extension-boilerplate

Stefan Van Damme

unread,
Oct 3, 2022, 1:38:40 PM10/3/22
to Chromium Extensions, na...@clint.digital, Stefan Van Damme
Hi there,

Great.

Thanks,
Stefan
Reply all
Reply to author
Forward
0 new messages