Chrome extension, popup does not display correctly for dynamic popup DOM modification - google-chrome-extension

I am building a chrome extension, a simple feature I want it to have is that when some clicks on the extension icon, it finds some info on the current page that my extension is visiting, and send the message from my content script to my popup, and my popup will add those info to it. now I pretty much finished all the work, there is only one problem left which is the layout of my popup does not display correctly. I have some thought about why it happens, I think it is because since the popup opens when you click on the icon, and then it finds the info on the page, and then it sends the message back to my popup, but the size of popup is already defined and displayed, so it does not rend it correctly, am I right? How should I fix it.

I think your content script should retrieve the info from the current page immediately (on load) and send this information to the background script.
The background script can store this information either in a variable, or in localStorage/Chrome storage. When opening the popup you can retrieve this information and show it immediately. This way you would avoid the racing condition.

Related

How to take screenshot of a tab in chrome extension

I am adding screenshot support to my extension, I want to take screenshot of a tab when a specific event is triggered, for example, a url is accessed. Now I am able to take screenshot of current tab using chrome.tabs.capturevisibletab, but the problem is that the event can be triggered by a tab that is not currently visible. So instead of visible tab, how can I take screenshot of any specific tab?
The method name is clear: capturevisibletab.
You can put the focus on the tab you want to snapshot, invoke the method and the restore the focus on the previous tab though.
You will need to add the <all_urls> permission in your manifest file.

How to keep extension pop up to remain open when new tab is clicked

my extension close when link in the extension is clicked
How to keep extension pop up to remain open when new tab is clicked
In general, that's not possible as stated in Chrome Extensions FAQ:
Can extensions keep popups open after the user clicks away from them?
No, popups automatically close when the user focuses on some portion of the browser outside of the popup. There is no way to keep the popup open after the user has clicked away.
However, if you inspect the popup, it will stay open as long as you don't close the Developer Tools window.
For end users, the only thing you could do is use a tab instead of a popup if that works better for your use case, or just inject your code into a specific tab to show your interface on top of/next to a page, as some extensions like Siteimprove do.

How do I download a file in Watir?

I'm starting to use Watir and I can't find anything about downloading a file (not an image, I've seen there's a specific method for that) and I don't care about configuring the download directory, nor where a button is clicked, just when I'm on a page, be it .html, .png, .rb how am I supposed to "Save as"? This really isn't made clear
I can right click on a link to a page but can't send_keys :down (it just moves the page down in the background of the right click context menu) as follows:
require "watir-webdriver"
browser = Watir::Browser.new :chrome
browser.goto "https://github.com/lmmx/watir-paper-scanner/blob/master/bookworm.rb"
browser.a(:text => "Raw").right_click
Edit: just put in the above code used to get an example of what I was actually trying to do as a little test, the last bit. .right_click works but .send_keys doesn't act on the context menu it produces, it moves the page instead, this could be substituted for some sort of .download function if there is one
What am I missing here...?
is the 'context menu' that is opening up actually a operating system level 'file finder' dialog? if so that is outside of the DOM and nothing based on webdriver is going to be able to touch it. at that point you are talking to the OS, not the browser. The browser has basically told the OS 'hey ask the user to pick a file and return the file path to me' and you the user are no longer interacting with the browser.
proof of this would be to right click on something in the dialog, if you do not see an 'examine element' option, you are very likely not in the browser.
at that point, look into something like RAutomation or AutoIt

Refresh page in browser without resubmitting form

I'm an ASP.NET developer, and I usually find myself leaving the webpage that I'm working on open in my browser (Chrome is my browser of choice, but this question is relevant for any browser). My workflow typically goes like this: I write code, I rebuild my project in Visual Studio, and then I flip back to my browser with Alt-Tab and hit F5 to refresh the page.
This is fine and dandy if a form hasn't been submitted since the page was opened. But if I've been clicking around on ASP.NET form controls, the page has posted form data a number of times, so hitting F5 causes the browser to (sensibly) pop up a confirmation message, e.g., "Confirm Form Resubmission: The page that you're looking for used information that you entered...".
Sometimes I do want to resubmit the form, but more often than not, I just want to start over with the page (rather than resubmit form data). The way I usually get around this is to simply add some query string data to the URL so that the browser sees it as a fresh page request, e.g.:
page.aspx
becomes
page.aspx?
(or vice-versa).
My question is: Is there a better way to quickly request a fresh version of a webpage (and not submit form data) in any of the major browsers? It seems like a no-brainer to me for web development, but maybe I'm missing something. What I'd love to see is something like the last item in this list:
F5: refresh page
Ctrl-F5: refresh page (and force cache refresh)
Alt-F5: request fresh copy of the page without resubmitting the form
Go to the address bar and press Enter to submit a fresh GET request. Quick keyboard shortcut is Alt+D, Enter.
Yes, just focus on address bar and press enter.
In Chrome, you can use Ctrl-L to focus on the address bar as well as the suggestions made above.

showing content on the blank screen after downloading a file

I've observed that under certain circumstances, a web browser will navigate to a blank page and then prompt the user to download a file. In my current situation, it's navigating to a URL that generates an Excel file. The download of the file works perfectly, but the user is now stranded on a blank page. There are two things I would like to figure out:
What causes the blank page to be displayed? It doesn't happen all the time. Is it the difference between using GET and POST (I can't recall seeing a hyperlink do it, but forms usually do)? Is it something to do with the Content-Disposition? In my current case, I've set the Content-Disposition to be "inline" because I want it to display in the browser in IE. Firefox (and presumably others) will of course prompt to download because they can't display it inline. It is the situation where the user chooses to save it that the blank screen results.
If it is possible, I'd like to display some content on this blank screen to provide the user with a message like "your file has been generated, click here to go back to the main screen" or somesuch. Is there a way I can do that?
I'm using an IIS extension written in C++, so solutions for ASP, PHP, etc will not be helpful unless they're generally applicable (though I wouldn't mind learning about solutions in those languages!). Thanks.
I think you practically answered your own question: setting content-disposition to inline does exactly that. One solution that comes to mind is browser detection: use inline disposition if the browser is IE, attachment otherwise.
BTW, as a user, I prefer sites which offer me a choice whether I want to download the file or view it inside the browser (when, for example, accessing a PDF file). In this case, I would consider having a link/button for downloading the file, and adding a second link/button for IE browsers to view it.

Resources