Chrome Extension: How to Display Current URL in Modal Window? - google-chrome-extension

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!

Related

How do you click a button in a browser popup window

I'm new to using Watir and have a problem. Within my browser page there is an option to add a note. This brings up a window within the browser which has the following id:
span id="ui-id-2" class="ui-dialog-title">Add Note</span
I can't work out how to use the controls within this window such as the 'Save' button as Watir doesn't seem to recognise either the window or the controls
So if I wanted to use same type of Save button within the main browser it would be fine; I'd just use browser.button(:id=> "Save").click.
Trying to use it within the popup though won't work as Watir can't recognise it within the popup. Any ideas appreciated!

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.

Force tab to render

Is there a way to force a certain tab to render, even without currently being the active tab?
The reason i need to do this is because my extension uses chrome.tabs to open multiple tabs and switch between them, and whenever I switch to a tab which has not yet been active, the tab has not rendered yet, which causes a white flash to appear on the tab until the tab renders. The duration of the white flash is also proportional to how heavy the web page is to render.
What I've noticed though, is that if you switch to a tab which was active at least once in the past, the white flash does not appear (since it has been rendered at least once in the past)
I need to force a tab to be rendered before switching to it, so that the white flash doesn't appear.
I am writing on chrome version 38 (due to technical restrictions)
Thanks
No. You can't control it.
The white flashing is indeed an annoying known issue.
The only wild idea that can be implemented right now:
create a new minimized window with a blank url or about:blank,
move the tab you need into that window via chrome.tabs.move
now that the tab is active Chrome should render it even in a minimized window
then after a while move the tab back and activate it

How to open the default popup from context menu in a chrome extension

I have developed a chrome extension that opens a popup when I click on the icon near the address bar. Everything works fine, however I want to add some functionality to it. So I thought I'd also add a context menu item so that the user can simply search for the highlighted word. I want the popup to showup when the user clicks on the item in the context menu(the default popup in the top right corner and not a new popup window or a new tab).
Can I have this functionality? If yes, how do I implement it?
You can't make the popup page show programmatically as if the user clicked it.
However, you can still have something display based on the background script / content menu click. There are 4 main options for your background script:
Open a new tab to the popup.html page
Programmatic injection of javascript to construct a popup-like dialog on the page
Content script message passing to do the same as above, using a running content-script.
Use the notifications API for a simple minimally stylized message to the user.
Options 2, 3, 4 will allow the user to stay on their tab without any navigation. The notifications API route is the simplest to use if you just want some quick notification to the user, and there are fewer security snags. 2 and 3 require more book-keeping, but you can make the dialog look like your popup.
There should be an API for it now (as in 2023)
https://developer.chrome.com/docs/extensions/reference/action/#method-openPopup
update: tried, but failed, there was a bug.
https://github.com/GoogleChrome/developer.chrome.com/issues/2602
hope they fix it soon.
I was looking for extensions that I have already been used, but forget its name. This extension opened up the result into Context Menu, without open new TAB or popup.
may be useful
https://developer.chrome.com/extensions/contextMenus

Yahoo UI the popup implementation with YAHOO.widget.Dialog

I used the Yahoo.widget.dialog to implement a popup window. Currently, it popups only on the page which is belongs. If I am working on the other (tab browser) pages. The popup window will be not seen.Could somebody supply some help for this ?Thanks
You could either switch to window.alert() or use window.open() to open a new pop-up window containing your content.
Neither one is something I'd personally want to experience, but those are your two options for opening a pop-up outside the page. Window.open will get caught by many pop-up blockers so you'll need to watch for that.

Resources