The My Opera forums have been replaced with forums.opera.com. Please head over there to discuss Opera's products and features
See the new ForumsYou need to be logged in to post in the forums. If you do not have an account, please sign up first.
an Opera refresher
hello,I searched for "refresher" and got no response. I also looked over these threads and they don't exactly cover what I need:
http://my.opera.com/community/forums/topic.dml?id=298220
http://forums.g4tv.com/showthread.php?t=170985
I am looking for a way to either develop (or buy, if it already exists) an application that refreshes a URL using Opera and every time it reloads the page, saves the HTML with a time stamp; e.g., My_Page_10_12_2011_08_00_15.html. (I don't really care what the file name format is. The important thing is that the reload should not overwrite the last page that was saved.)
I am not sure if this is a request for an extension or a widget.
You can purchases refreshers that reload pages and save HTML for IE. However, I don't see any that do this for Opera.
There's another possibility I have been thinking of. Is there an application available for Blackberries that could allow you to configure a hot key (e.g., F10) that reloads an Opera browser, does a View/Source and saves the HTML using a system-generated name. The trick again is that the file name should not overwrite the previous one.
Opera is my browser of choice.
thanks,
Extensions would be ideal for this, but they unfortunately can't access the file system at all.
Originally posted by spadija:
Extensions would be ideal for this, but they unfortunately can't access the file system at all.
What about File I/O API (http://dev.opera.com/libraries/fileio/)? Is it strictly for widgets?
1. Develop it as widget + use File I/O API for saving files. This is very easy to implement, the only drawback is that widget can not get url from address bar of browser automatically, user will need to enter url manually in widget interface. Widget docks: http://dev.opera.com/articles/widgets/, File I/O API docs: http://dev.opera.com/articles/view/file-i-o-api-for-widgets/
2. Develop it as extension + connect to the following Unite app for saving files: http://unite.opera.com/application/332/
3. Heavy hammers that always work: extension + use NPAPI plugin or Java applet for saving in files. Drawback: neither plugin nor applet can be embedded directly into oex file.
Develop it as widget + use File I/O API for saving files. This is very easy to implement, the only drawback is that widget can not get url from address bar of browser automatically, user will need to enter url manually in widget interface.
When you say "need to enter url manually in widget interface" are you saying that I need to type it in? Or, can it be entered once in a config file?
Also, if you (or anyone else) can point me to an example(s) of widget(s) using the file I/O I'd appreciate it. That would help me with the learning curve.
thanks!
Originally posted by cafescott:
When you say "need to enter url manually in widget interface" are you saying that I need to type it in? Or, can it be entered once in a config file?
It can be done either way.
I see my task in building this refresher widget as reading the HTML from a particular URL into memory and then writing it to a HTML file using the File I/O library. However, I don't want to read the HTML using the Microsoft.XMLHTTP class. From past experience the code I've written using XMLHTTP has pulled the HTML into memory as if it were from an IE browser. I really want to convince the source web site that I am reading the HTML in from an Opera browser.
I've taken a look at the Opera libraries:
http://dev.opera.com/libraries/
Maybe I'm missing it, but I don't see a library routine that reads HTML from a URL.
Does anyone have an idea how to read HTML from a URL and appear to the host website that I'm doing this from an Opera browser?
thanks,
Alternative is to go with extension. Extension can get html from document.documentElement.outerHTML. But it will be more difficult to implement saving file in extension.
* * *
<!DOCTYPE html>
<head>
<title>Refresher</title>
<script type="text/javascript" src="js/jquery-1.6.4.js"></script>
</head>
<body>
<script type="text/javascript" >
$(document).ready(function() {
$.support.cors = true;
alert('after support statement');
$.get('http://www.yahoo.com', function(data) {
$("#result").html(data);
alert('Load was performed.');
});
});
</script>
<div id="result"></div>
Do we see anything?
</body>
</html>
* * * *
I get the Javascript alert after setting $.support to true. However, at that point nothing happens. I see the statement "Do we see anything?" on a blank page.
Does anyone have any ideas about how to grab some external HTML and display it on a locally-run browser? thanks.
Originally posted by cafescott:
does $.support.cors play nice with Opera?
You can only do cross-site requests inside the context of an extension with permission to do so ( i.e. from the background process with <access origin="*" /> in config.xml)
Trying to do this from a regular webpage is subject to normal security restrictions, and Opera doesn't yet support CORS, so you can't do cross-domain XHR requests from a normal webpage.
The $.support.cors = true line is there only to make jQuery aware that it can do cross-origin requests, otherwise it short-circuits the request with an error without even sending it. So this is more of a case of incorrect assumptions in jQuery and not actually enabling CORS in the browser.
See also:
http://my.opera.com/community/forums/topic.dml?id=988782
I apologize for the fact that you keep telling people the same thing about cross-site requests. Is there any particular place where the origin="*" statement goes in the config.xml?
I made a simple widget. When it runs I get a white screen with my text: "Do we see anything?" The URL doesn't load. The two alerts don't execute. (BTW, any tips on how to debug widgets?) Here's my stuff.
index.html:
<!DOCTYPE html>
<html>
<head>
<title>Refresher</title>
<script type="text/javascript" src="js/jquery-1.6.4.js"></script>
</head>
<body bgcolor="#FFFFFF">
<script type="text/javascript" >
$(document).ready(function() {
$.support.cors = true;
alert('after support statement');
$.get('http://online.wsj.com/home-page', function(data) {
$("#result").html(data);
alert('Load was performed.');
});
});
</script>
<div id="result"></div>
Do we see anything?
</body>
</html>
config.xml:
<?xml version='1.0' encoding='utf-8'?>
<widget defaultmode="application" network="public">
<widgetname>Simple Refresher</widgetname>
<access origin="*"/>
<description>Loads HTML and saves it.</description>
<width>800</width>
<height>1000</height>
<author>
<name>John Doe</name>
<email>nope@nowhere.com</email>
<link>http://nowhere.com</link>
<organization></organization>
</author>
<id>
<host>http://online.wsj.com/home-page</host>
<name>Simple Refresher</name>
<revised>2011-10-19</revised>
</id>
<feature name="http://xmlns.opera.com/fileio" required="true"/>
<security>
<access>
<protocol>http</protocol>
</access>
<content plugins="no"/>
</security>
</widget>
Any help is greatly appreciated. Thanks.
20. October 2011, 01:04:12 (edited)
I've encountered a problem that maybe someone here can help with. My little widget now does a pretty good job of refreshing a page. However, there are differences between the page that the widget accesses versus what I obtain using another Opera browser. I think this is because the website delivers different content based on whether the request is asynchronous or not.
I have found this page:
http://stackoverflow.com/questions/6849686/how-to-change-ajax-default-settings
It recommends this code:
$.ajaxSetup({
async: false
});
Unfortunately, it doesn't work. A good example is yahoo.com. My widget doesn't match what shows up when I use another Opera browser. Here's the code. (The config.xml is the same as what I posted earlier.)
index.html:
<!DOCTYPE html>
<html>
<head>
<title>Refresher</title>
<script type="text/javascript" src="jquery-1.6.4.js"></script>
</head>
<body bgcolor="#FFFFFF">
<script type="text/javascript" >
$(document).ready(function() {
$.support.cors = true;
$.ajaxSetup({
async: false
});
var intI = 0;
var refreshId = setInterval(function(){
$.get('http://www.yahoo.com', function(data) {
$("#result").html(data);
intI = intI + 1;
$("iteration").html(intI);
});
});
},600000);
</script>
<div id="iteration"></div>
<div id="result"></div>
Do we see anything?
</body>
</html>
Is it possible to still use "get" and make a synchronous request? Or, do I have to throw away the elegance of it and use the more clunky versions of retrieving a URL? (Will this clunky code actually work?)
<edit>
Of course, another problem is the idea of iterating based on setInterval or setTimeout. My understanding is that these calls are inherently asynchronous. So, it may be impossible to repeat a synchronous get HTML request.
</edit>
Many thanks for help.
I simplified my code to:
$(document).ready(function() {
$.support.cors = true;
$.ajaxSetup({
async: false
});
$.get('http://www.yahoo.com', function(data) {
$("#result").html(data);
});
});
I am still making an asynchronous request. This suggests:
1. $.ajaxSetup ({ asynch: false })
Is not working;
or
2. It is impossible to call "$.get" synchronously.
Well, I sure hope JQuery offers a truly synchronous solution. thanks for reading; and thanks for the help.
You could just use $.ajax directly - i.e. :
$.ajax("http://www.yahoo.com", {async: false});
That being said, I highly doubt there would be a difference between data sent with a synchronous or asynchronous request, the server has no way of distinguishing between them, they are identical (you can verify this using dragonfly's network tab or Wireshark). Synchronous requests block the event thread (script execution, UI), so there is really no good reason you would ever want to use synchronous requests.
What is more likely happening is that the widget and the browser use different cookies, so you may be getting a "plain" page in the widget and a "personalized" page in the browser, where you are logged in. Widgets do not have access to cookies set in the browser, widgets run as standalone browser instances with a seperate cookie store.
There is an option for extensions to get shared cookies from the browser (requires a cookie sharing permission), so you can get cookie-customized (i.e. logged in) content from the background - see Cookie sharing in Opera extensions.
Another possibility is that yahoo's front page uses a lot of javascript widgets which are only displayed as a result of scripts modifying the DOM on the page. Just doing an ajax request to the page will only load the raw HTML of the page, so javascript widgets will not be displayed.
(It would be interesting to experiment by using the Ajax syntax that specifically includes a statement about a synchronous call; but at this moment I have no reason to believe it would produce anything differently.)
I'm trying to get it to reload every 30 seconds or so and in so doing have screwed up the project. All its doing right now is showing a black screen. (btw, ever have a PC that is running so slow you just want to shoot it? That's what I'm experiencing now.)
Thanks again for the big help. Here's my index.html right now. (I understand that the asynch initialization can be removed as it is not doing anything.)
<!DOCTYPE html>
<html>
<head>
<title>Refresher</title>
<script type="text/javascript" src="jquery-1.6.4.js"></script>
</head>
<script type="text/javascript" >
$(document).ready(function() {
$.support.cors = true;
$.ajaxSetup({
async: false
});
var intI = 0;
var refreshId = setInterval(function(){
$.get('http://www.yahoo.com', function(data) {
$("#result").html(data);
intI = intI + 1;
$("iteration").html(intI);
});
});
},30000);
</script>
<body>
<iframe id="iframeID" width=600 height=1000>
<div id="iteration"></div>
<div id="result"></div>
</iframe>
</body>
</html>
One more thing. Earlier you wrote that you want to get html of document in the same way as user sees it after right click -> view source. If this is your task - then you should not use iframe or find other ways to execute javascript on page. You should just get response of ajax - this will match view source content (and this is closer to how search engines see page). Of course, it will not include various changes done by javascript.
Let's wait first whether cafescott will be able to get html from iframe. If widget will allow this - of course, it will be preferred solution.
In addition, there is a very handy Opera extension called "Source" which is available from Opera's extension library. Once installed, Ctrl-F9 gives you the page source. Ctrl-A selects all text, Ctrl-C copies it. At this point you can start Notepad. You have to change from ANSI to Unicode format before saving. (I don't know if Autoit can choose Unicode from the list. If not, perhaps there is a way to configure Notepad, or something similar, to always save in Unicode.) Hopefully AutoIt can do these things.
I've tested both saving methods with yahoo, and I haven't detected any differences between what the browser originally shows and what the HTML page displays (when you drop it into a blank browser). If AutoIt can handle which ever method is used for saving, there is no reason to pursue a complicated JQuery solution which might ultimately be elusive.
I've appreciated all the help. This is a nice forum for information. Thanks Sergey-pyprev, Spadija and d4n3.