AutoIt wait for Chrome to load - autoit

Using AutoIt, how can I determine when a chrome browser has finished loading? Any working examples are highly appreciated. I read there was a way with checking pixel colors, but that doesn't seem very efficacious.

If you are opening Chrome using AutoIt and immediately navigating to a specific web page everytime, then one option is to run a loop checking for particular content on the page (such as copyright text in the footer).
A rough skeleton of the code might be:
Opt('WinTitleMatchMode', 2) ;ensure partial window title matches on and WinActivate, WinExists, WinWait, WinWaitActive, WinKill commands
; code to load chrome via Run dialog goes here
WinWaitActive("Chrome")
sleep(500)
send("^a") ;select all on the browser's active tab
sleep(250)
send("^c") ;copy it into the clipboard
sleep(250)
Local $webPageContents = ClipGet()
; if statement or while loop to check for the existence of some string of content on the webpage
Unfortunately, this won't actually determine if the page has returned with an http 200 status response and all assets/images are fully loaded, but might suffice.
If you absolutely need to know that the page has fully loaded, you'd probably want to script opening the Web Inspector/Dev Tools and navigating to the Network panel, reading the Network Requests data repeatedly every couple seconds for until the previous state and current state match to determine the page has finished loading all its assets.

Related

CSS stops working in Chrome after opening console

I'm making an app with node.js and have a few html pages that are styled with one css file. After I click on a link (to a subpage) on the home page and open it in a new tab, everything seems fine. However, after I push ctrl+F12 and open the console, the css styles somehow 'stop working', which means:
the elements are not styled, even though there is the link tag with style.css in 'Elements' tab in html
In Network tab, I can only see style.css file with status 304 listed there (all other js files are not there, even though JS scripts work)
When I return to the home page, the css styles are not visible as well (they were before new tab was open, now it's 304 status in Netwok). After refreshing, styles go back (along with status 200).
After I refresh the subpage, everything is fine again, opening console does nothing to styles (Network tab shows all the files, including style.css with status 200). After closing/ opening console again, everything is okay too.
If I dont't refresh the subage, the styles "come back" when I change window size (although not immediately, after a second). Otherwise there's just html with working js scripts.
This happens only in Chrome (version 53.0.2785.101), only after opening console for the first time. I have no clue why this might be happening.
Please help!
Ok, I managed to solve this. This issue seems to be Chrome bug, discussed for example here:
https://bugs.chromium.org/p/chromium/issues/detail?id=647151
https://bugs.chromium.org/p/chromium/issues/detail?id=648023
I am not sure whether my solution is perfect, but it now it seems to work. I just added one option into express.static in my server.js (I use Express JS):
app.use(express.static('public', {maxAge: '5d'}));
I guess the max-age property is crucial here - it's specified in Cache-Control http header (you can see this in Dev Tools console in Network tab, after clicking on given file). Found this solution mentioned in the first link. If I see further issues, I will update this answer.
I'm sorry I can't explain this problem in details.
Edit: this solution has one major flaw: when I edit my files, the browser still loads the older versions. Therefore, I turn this max-age property off when I wish to see the changes in files. If anyone has better fix, please share.
Try clearing your cache in chrome, then restart chrome and try again.
(A 304 response header is not an error necessarily. It just means that the browser should load the resource from cache. Basically the browser says "Hey, Can I use the same copy of that CSS file that you gave me last time, or has it changed?" and the Server says "It hasn't changed, go ahead and use the copy you have" AKA 304)
If that doesn't fix the issue, you may look into ETags

Trying to persist CSS changes to file on disk in Chrome Dev tools

I have just started exploring the possibility of saving changes made to a page and it's styling in Chrome Dev Tools on the fly.
I've followed this short video tutorial on mapping the project files on disk to the Dev Tools via the Sources tab. Everything works fine until around the 5:17 point where he selects an element in the Elements tab and makes several CSS style changes which automatically persist to the file on disk.
This doesn't work for me. The changes won't save to the file and when I refresh the page reverts to the original styles. I have checked to see if there is an asterisk beside the corresponding CSS file in the Sources panel, to denote changes have been made, but there is nothing there.
I have also tried the solution posted in this SO question but I don't see the link to the stylesheet after editing the style in the Elements tab that will redirect back to the file in the Sources tab allowing the changes to be saved.
Can anyone tell me what I am missing? Thanks!
You need to make sure you map your Workspace to a Network Resource to persist changes automatically. I have produced the steps below to get this working correctly.
Select the folder in Sources and click 'Add Folder to Workspace'
If you open up our stylesheet in Sources and go to the Elements panel to make changes, upon coming back you will see a separate instance of the stylesheet opened with pending changes. The reason is that Chrome doesn't know how to map the URL to the file on your system yet.
Select 'Map to Network Resource...'. You will notice that 'top' disappears.
Make a change in the Elements panel now. When you go back to the Sources panel, the changes will automatically be shown without requiring any explicit save.
You can see exactly what was done by going to the Workspaces section of the DevTools settings panel. We've added a local Workspace, and then mapping the URL, which in my case is on my computer and accessed with the file:// protocol, to the relative path on the system.

Possilble to auto open a downloaded word document downloaded in browser

The requirement is sent a Word document from browser, and automatically open it on MS Word so that then can view and edit the Word document.
The only solution I can found require the end user to click a dialogue Window in order to open a Word document in Office when the document is download from browser.
Is this the only way, that the user has to click a dialogue Window before Office can open the downloaded Word document?
It kinds of make sense for security reason to not let browser automatically execute an local application (Word.exe) on the local machine, but I still want to confirm that.
If the answer is yes, then I would like to know how to do that?
Edit: I just found out that you have to use inline instead of Attachement, otherwise it will always ask for the option event the browsers are setup properly.
Response.AddHeader("Content-Disposition", "inline;filename=clientquotes.docx");
After made that change, browser will auto open the Word document without asking for action.
If I understand correctly, you want to change the behaviour of your browser to automatically open downloaded files. As far I'm aware its pretty painless process when it comes to Firefox and Google Chrome, however on IE it's not as simple.
Firefox
Changing download actions
This will not affect media embedded in a web page - only links to the files themselves.
Click the menu button Menu and choose Options
Select the Applications panel.
The Applications panel will display. Select the type of file for which you want to change the default action.
The Action column will give you a drop-down menu, with options on action to take, whenever you click that type of file.
Alwaysask: will prompt you to select what action you want Firefox to take when you click on that type of file. This can be useful if Firefox is automatically saving a file type or is always opening it with a certain program and you want to be asked what to do.
Save File: will always save the file to your computer using the Downloads window, whenever you click that type of file.
Open the file with an application or plugin of your choosing.
Click Ok to close the options window after making changes
Adding download actions
On the web, find a link to a file matching the type you want to add.
Click on the file link to download it.
Select how you want Firefox to handle the file:
Open with: Saves the file to a temporary folder and opens it in the default application for that file type. To select an application, click Browse....
Do not choose Firefox to always open a certain file type, as doing so can cause
a problem where Firefox repeatedly opens empty tabs or windows after you click on a link.
Save file: Saves the file to the download folder (specified in the Firefox General panel).
In the Opening file window, check mark Do this automatically for files like this from now on.
Click Ok.
Is Do this automatically for files like this from now on disabled?
This can happen if the website's server incorrectly specifies the
Internet Media type of the file. It also can happen if the server assigns
"Content-Disposition: attachment" to the file.
Reference
Google Chrome
If you want certain types of file always to open after they've finished downloading, click the arrow next to the file button in the downloads bar and select Always open files of this type.
Reference
IE
From what I can gather for IE you will have to change the registry keys. You can refer to this link for further information.
I hope this answers your question.

Chrome caching CSS but not loading images inside CSS file

We're having a weird problem at work that happens only in chrome. It looks like the css file is getting cached and the content of this file isn't getting re-downloaded.
The problem is that when using a fresh session for example "private session", the image "mainSprite.png" isn't getting displayed.
After some tests, I believe the problem is related to us doing redirects at the beginning if the user isn't authenticated. From what I understand, it might not complete the download of the sprites linked inside the css files. It will cache an invalid object as soon as the redirect starts and then on the following pages, it will fail to display a correct image since it cached something wrong.
The strange thing is that it actually loads the image completely at some point. But it looks like it's not refreshing it in memory...
I did a timeout of one second before starting redirects on first load and images correctly display. This is a quick fix and I can't expect every computer to load in 1 second every images contained in the css.
edit
As far as I can say, it really looks like a race condition. I changed the order of loading. We use require.js. Instead of loading js after css, I start js loading before. And images are getting loaded correctly now on my local server.
if someone is interested to look into it:
http://api.checklist.com
edit 2
When images aren't visible, opening new tabs will have the same problem. Closing the browser and reopening it will work on first load and images isn't being downloaded but loaded from Cache which means that before closing the browser, the image was indeed downloaded.
It looks like the problem coming from your redirects unfortunately i couldn't see your example ( link won't open ). Google chrome has indeed issues with caching it's annoying during development time ( clear up the cache, load new image, do the same for new image..), if you need to clear your cache try the folowing:
try to go to
chrome://chrome/settings/clearBrowserData
in your chrome browser and check the options:
Empty the Cache( i have also Clear download history and Delete cookies and other site and plug-in data )
click on 'Clear Browsing Data' button it should
All what you need to do is to trace your cash list via chrome, and from what I see is that you got this error which make it not cached:
Uncaught TypeError: Object [object Object] has no method 'placeholder'
So if you want to trace, you can use the manifest offline mode or you trace via your code.
Just following and test your page, I did catch where the error is:
file: scripts2.js Line 20 --> $('input[placeholder]').placeholder();
which you need to check the name of the place holder and change it here in this tag.
Thank you
I assume your server/backend app has routes set up. Like this Play! framework example:
# Ignore favicon requests
GET /favicon.ico 404
# Map static resources from the /app/public folder to the /public path
GET /public/ staticDir:public
# Catch all
* /{controller} {controller}.index
According your summary I suggest to set up a static folder route (where the images are) in config file or htaccess as you want, then check image url in browser url bar (with empty session). That should work!
First I would suggest that you first try to find ways to narrow the redirects. If it possible I would suggest that it would be much more advisable to try to create your content dynamically based on your users authentication using languages like PHP or ASP (just to name two).
The classic way of disabling the caching on a webpage is to set two <meta> tags inside of your <head> </head> tags. However, you should note that these are technically not "correct" as they are not part of any of the "offical" standards documentation. This also means that I would again lean towards my first suggestion of finding a better delivery system which in turn should prevent the problem.
So for "testing" purposes the tags would be:
<HEAD>
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
<META HTTP-EQUIV="EXPIRES" CONTENT="0">
</HEAD>
Maybe I don't understand your question or dilemma (maybe because of lack of explanation or because I can't see your page at that link since I run Chrome), but there's an example I ran across here that works in Chrome by just using Javascript/jQuery to load, instead of CSS:
http://jsfiddle.net/2Cgyg/6/
Use image at URL: http://www.w3schools.com/cssref/img_tree.gif
And although the accepted answer didn't work for me in Chrome, this is the question I got the jsFiddle above, from:
Load Image from javascript
All the caching, etc. is unnecessary, and even something you wouldn't want to do if your images are ever updated to something else - they won't appear without forcing a refresh which you can only do through altering the file name like this to avoid users not seeing your updated image:
myPic.jpg?MMDDYYYY
And you could set the date according to the date you are modifying it.
clean your browser history like cache,cookies
clean the temporary internet file
if problem not solved then reinstall browser your problem is solved definitely

Qt, PDF viewer, and jumping to specific pages

I've spent a couple of days searching the bowels of the internet to find out the answer to my question, so since I can't find the answer I'm throwing it out to the masses...
Within my Qt application I'm able to open a PDF using the OS default viewer thru the following command:
QDesktopServices::openUrl(QUrl("file:////C:help.pdf", QUrl::TolerantMode));
This works fine because all I'm wanting to do is display a help file to a user, but when I try to add a "#page=20" parameter to my URL, the document still only opens to the first page, not page 20. If I cut and paste the command into a browser it jumps correctly.
So -- my questions are:
Would poppler or another viewing tool allow me to jump to a page?
Is there another way with Qt to jump to a page? Or maybe another command to open the file instead of with QDesktopServices?
edit: I tried with QProcess and that doesn't jump to the page either -- not that I expected it to...
Use QProcess with one of the answers from Adobe Reader Command Line Reference :
<path to Adobe Reader> /A "page=100" "<Path To PDF file>"
Yes. evince, for example, takes option --page-index which you can set page number
No. QDesktopServices::openUrl() ends up calling one of helper commands, such as xdg-open or kfmclient, without any arguments.
Of cause, you can always use libpoppler in your app to open your PDFs. Poppler::Document::page() is your friend.
Another solution I was able to work out was to convert my PDF to HTML, create a QWebView, and display the HTML there. I then added an ID attribute to the HTML doc, and when I tacked that ID to my URL it loaded into the widget at the location of the attribute...
scott

Resources