how to get website's site from chrome extension - google-chrome-extension

I am using this code for the Chrome extension to get the window's width in the background script
chrome.windows.getCurrent(function (wind) {
const w = wind.width;
});
but that sizes the entire window. If I have open and nested the devtools, it will be inside that window.
How can I instead get the size of only the website's width?

Related

Set browser window position puppeteer

Is it possible to move the position of the browser window?
As in selenium driver.set_window_position(-10000, 0)
Setting the browser position at startup is not suitable, it is necessary during operation

Customize Chrome Tab Width From Extension Background Script

Is it possible to resize the width of the tabs for a tab opened with chrome.tabs.create, something like
chrome.tabs.create({url: url});
chrome.resizetab(width); //maybe something like this
Also, can we make the tab title blank and show only the favicon instead of showing "Untitled"?!

Light & Dark browserAction icons in Chrome 51

In Chrome 51, incognito windows now have a dark toolbar background, while previous versions used a light background. It's generally infeasible for a single 16x16 image to provide good contrast in both situations:
When displaying information to the user through a browserAction icon, by what mechanism can an extension provide dark-themed and light-themed icons, and switch between them depending on the current toolbar color?
Link to source code for the pictured extension
There is no such simple mechanism (yet), and it sounds like an excellent feature request to make at the very least for the manifest.
It's possible to approximate this though, by detecting incognito tabs being open and replacing the browser action icon for that tab only.
var incognitoIcons = {
19: "incognito19.png",
38: "incognito38.png"
};
chrome.tabs.onCreated.addListener(function(tab) {
if (tab.incognito) {
chrome.browserAction.setIcon({
path: incognitoIcons,
tabId: tab.id
});
}
});
If you're using a "split" incognito behavior (non-default), you can simply detect that and change the global icon for the incognito instance:
// Somewhere in background during initialization
if (chrome.extension.inIncognitoContext) {
chrome.browserAction.setIcon({path: incognitoIcons});
}
Note that content scripts can always rely on inIncognitoContext, so if you trigger a browser action icon change from them you can pass that along.
Obviously, you can do that with imageData instead of path, as is your case.
You may want to check the Chrome version while you're at it; I'm not aware of a better way than mentioned here.

Make Chrome Extension Browser Action Popup bigger than browser window

In FireFox extensions, the Panel/Popup that opens on the Toolbar sizes itself outside the browser window, if needed, so that we see every populated elements in the panel. In Chrome however, the popup/panel is only drawn until the browser window's boundaries. So, if the user resizes the browser window small enough, you don't see the entire popup.
I checked the documentation and couldn't find anything. Is there anything that can be done to show the entire popup?
This seems to be OS-dependent (can be reproduced on Linux and Win7, but not Win10).
As an extension author, there is nothing you can do to control it, this is just how the browser renders its content. You could submit a bug report.

Chrome Extension: How to Display Current URL in Modal Window?

I'm trying to create a chrome extension that will allow me to display the current URL in a modal or popup window. The URL will be enlarged so that it is easier for students to see in the classroom. My goal is to get away from my current method, which is to copy/paste the URL into notepad and enlarge the font so that students in the back of the room can see it. It would be great if I could simply click on an extension and have the URL displayed in a nice large font. Unfortunately, this is the first chrome extension I've ever written, so I'm running into all sorts of n00b issues.
Anyway, I've gotten close by following this post:
How can I get the URL of the current tab from a Google Chrome extension?
Here's my code:
chrome.tabs.getSelected(null,function(tab) {
var tablink = tab.url;
document.write("<h1 style='font-size: 100px;'>" + tablink + "</h1>");
});
The problem is this code opens the URL in a popup with a horizontal scroll bar.
I either need to:
figure out a way to turn on word-wrap (to eliminate the scroll bar) ... or
adjust the width of the popup window so that it takes up the entire width of the screen ... or
find a different window solution (modal, new window that's alwaysOnTop, etc)
I tried chrome.windows.create but I couldn't figure out how to adapt the code above to use chrome.windows.create, and I also couldn't figure out how to make the resulting new window have active focus (focused: true didn't seem to work for me).
I also read that chrome.tabs.getSelected has been deprecated and I should be using chrome.tabs.query. However, I've had trouble getting the query method to work.
Again, this is my first chrome extension, so your patience, understanding, and help is greatly appreciated. Thanks!

Resources