cherrypy.session won't work on Chrome but works on Firefox - cherrypy

I run a web with CherryPy (version 3.2.0) and use cherrypy.session to store session specific data. It works perfectly with Firefox. However, I noticed that cherrypy.session would run in problems on Chrome. Basically, it looks like session variable resets when the consequent pages are being browsed.
I believe my config is set correctly
tools.sessions.on = True
tools.sessions.storage_type = "ram"
tools.sessions.storage_path = "/home/dmitry/test/sessions"
tools.sessions.timeout = 60
tools.sessions.name = "test"
What can lead to such a browser-specific problem?

I guess by now you've figured out the solution, but one possible cause can be that the development server is running on localhost, and chrome refuses to set cookies. You have to set up exceptions to make it work. Searching Google for this issue brings up some promising results.

Related

intern-runner just hangs ('/client/end' publish/subscribe doesn't work?)

When launched through the intern-runner command, my tests are still hanging--intern-runner never exits to give me a report and I can tell that the proxy server is still running on port 9000. The browser I specified through my config just remains open (and no, I did not set leaveRemoteOpen to true). I added some debug to lib/reporters/webdriver.js, because I saw that's what logged the "Tests complete" message. I could see that the topic.publish('/client/end') code was invoked, but nothing ever responded to this event. Doesn't lib/ClientSuite subscribe to this topic? From that module:
topic.subscribe('/client/end', function (sessionId) {
console.log("subscribed to '/client/end' for session", sessionId);
if (sessionId === remote.session.sessionId) {
clearHandles();
// get about:blank to always collect code coverage data from the page in case it is
// navigated away later by some other process; this happens during self-testing when
// the new Leadfoot library takes over
remote.setHeartbeatInterval(0).get('about:blank').then(lang.hitch(dfd, 'resolve'));
}
})
But nothing ever happens, and I don't see my console.log() output. Sorry if I am bringing up things that are red herrings, but I just wanted to do some initial investigation first.
All I want is for my test to end and my JUnit and LCOV reports generated! :( What could be going wrong?
And note: no error messages are logged to the command terminal from which I invoked intern-runner config=unittest/myInternConfig. No errors (obvious ones at least) appear in terminal where Selenium server is running.
Update 03/15/15: I added this info in my last comment, but maybe comments get lost in the shuffle on Stackoverflow. In our legacy DOH tests, we used Sinon to fake a server so as to not make real I/O requests to the backend server in unittests. I didn't see a problem with keeping this in the Intern tests, but apparently, there is. When I disabled the test modules that just do
var server = sinon.fakeServer.create();
(well, that, in addition to calling server.respondWith() and server.respond())
intern-runner completed, I got my reports, and etc. Then I searched for "intern with sinon" and stumbled upon https://github.com/theintern/intern/issues/47, where jason0x43 linked to his Sinon-with-Intern code at https://github.com/theintern/intern/blob/sinon/sinon.js. So, I found that very helpful--it seems that in my situation, Sinon's FakeXMLHttpRequest was ALSO faking requests to Intern's proxy server, and that was what was hanging the process.
So, after pretty much using jason0x43's sinon.js code to filter out the "real request," I re-enabled the problematic test modules, re-ran, and everything worked beautifully.
Again, no errors or any sort of warnings reported in terminal or browser console--it would be great if there could be some sort of head's up about this pitfall. Even if just in a Readme file.
(I also edited my original post to add this info.) In our legacy DOH tests, we used Sinon to fake a server so as to not make real I/O requests to the backend server in unittests. I didn't see a problem with keeping this in the Intern tests, but apparently, there is. When I disabled the test modules that just do
var server = sinon.fakeServer.create();
(well, that, in addition to calling server.respondWith() and server.respond())
intern-runner completed, I got my reports, and etc. Then I searched for "intern with sinon" and stumbled upon https://github.com/theintern/intern/issues/47, where jason0x43 linked to his Sinon-with-Intern code at https://github.com/theintern/intern/blob/sinon/sinon.js. So, I found that very helpful--it seems that in my situation, Sinon's FakeXMLHttpRequest was ALSO faking requests to Intern's proxy server, and that was what was hanging the process.
So, after pretty much using jason0x43's sinon.js code to filter out the "real request," I re-enabled the problematic test modules, re-ran, and everything worked beautifully.
Again, no errors or any sort of warnings reported in terminal or browser console--it would be great if there could be some sort of head's up about this pitfall. Even if just in a Readme file.

Chrome Extension: How to solve "Not allowed to load local resource" error upon content script injection

I tried to inject jQuery to content page to make easy access to DOM elements.
The code was something like below
chrome.tabs.executeScript(tabId, { file: "jquery.min.js"} ,function(){
chrome.tabs.executeScript(tabId, { file: myOwnScript.js});}
);
It was all fine on Windows, but on Ubuntu, in content page window, I always get console error message saying
"Not allowed to load local resource: file:///****/jquery.min.map"
I noted it was talking about *.map but not *.js
There are some more mysteies:
1. There is no error message on myOwnScript.js
2. My extension works well even though this message keeps showing at each page load.
I made plenty searches on Google but didn't find similar case.
My questions is,
1. What is the reason of such error?
2. Should I take it as a serious error?
My enviroment is as below
OS : Ubuntu 14.04, with LXDE desktop
Chrome : 34.0.1847.132
(Didn't try other configurations because I am not that good at customizing Linux :)
Previous versions of Jquery have a comment pointing to the map file (so that a bug in jquery.min.js can be translated to a bug in the readable jquery.js). You can safely delete this comment, or upgrade to a more recent version of Jquery, which has removed this comment (for exactly this reason). See also this answer.

NodeJS: Express: node-blade: Live UI

I am using Node.JS/express and node-blade (npm blade) as the template engine.
I'm trying to take advantage of the fantastic Live-UI feature set in Blade, but can't seem to get the Live updating views working; i.e when rendering content into an element any changes to the Model after the initial render are not reflected in the view.
The client side isn't throwing any errors, and events such as {click} and {change} work in the templates, but the view won't update to any changes in the Model without re-rendering the template.
On the browser;
systemVM = new blade.Model({test: 'stackoverflow'});
$('#wrap').render('pub/login', systemVM);
In the template;
h1 Hello #{test}
input
{change}
test='World!';
Have also tried; (on the browser)
systemVM.observable.test = 'World';
And; (on the browser)
systemVM.observable.test = 'World';
systemVM.invalidate('test');
And; (on the browser)
systemVM.observable.test = 'World';
systemVM.invalidate('test');
systemVM.sync();
Has anyone had experience getting this going?
It's also worth mentioning that the file 'plugins/deps/deps-utils.js' was missing from the spark-standalone.sh build script for using Meteor's 'Spark' and while spark built without it and isn't throwing any errors, I can't help but think that might be the issue. Have tried building spark-standalone from historical git commits, but every time the build throws errors.
Any help would be really appreciated, this is driving me crazy!
Issues were resolved by the standalone Spark.js file found at http://icomputeconsulting.com/spark.js (hope BMiner doesn't mind me posting this link)
Use this link: Un-official GitHub Repo

WebGL local textures and cross-domain

I wrote a webgl program which works well with a local server, and now, I would like to run it locally.
But I had errors and after some researches, I found that it's a cross domain issue in loading textures.
function loadTexture( path ) {
var texture = new THREE.Texture( texture_placeholder );
var material = new THREE.MeshBasicMaterial( { map: texture, overdraw: true} );
var image = new Image();
image.onload = function () {
texture.needsUpdate = true;
material.map.image = this;
render();
};
texture.deallocate();
renderer3D.deallocateTexture( texture );
return material;
}
I tried several solutions :
github.com/mrdoob/three.js/issues/1305
github.com/mrdoob/three.js/issues/944
gist.github.com/ekeneijeoma/1186920
github.com/mrdoob/three.js/wiki/How-to-run-things-locally (the 1.Change security for local files in a browser (access page as file:///example))
I precise that I have no problem on Firefox, it works without changing anything.
The only solution which works on Chrome is to launch it with --allow-file-access-from-files.
And on IE, I don't know how to solve it, I enabled in the browser security options "Access data sources across domains" and "Navigate sub-frames across different domains" (http://msdn.microsoft.com/fr-fr/library/ee797612(v=cs.20).aspx) but nothing. I use IEWebGL and I have noticed that on http://iewebgl.com/, "IEWebGL v1.0 Released" section, it's written "- Secure (no local content loading, no cross-domain textures)". So maybe it can't be solved on IE due to IEWebGL !?
So what would be the solution for IE, if there is one? And is there a way to solve the problem by changing the code, without lauching a local server or Chrome with special option?
Thanks!
this question has been asked and answered at least 6 other times and is even answered in the three.js wiki.
The short of it is you need to run a local server. Open a terminal/shell/command prompt and type
cd <path/to/files>
python -m SimpleHTTPServer
Then in your browser go to
http://localhost:8000
Why is that not an option? It's simple and it solves the problem. It also doesn't leave your browser open to getting owned.
Here's several simple servers you could use
thanks for your answer.
Indeed, it has already been asked and solved, I saw the solutions and it works well with a local server, and I totally agree with about security.
I was asking that because, firstly, it works without any server on Firefox and Safari, and on Google with --allow..., so if it was possible on IE, it would have been good. And secondly, because I wanted a very simple program which works quickly without having to install python or something else for a server,...
In fact, it's for an offline application (I know it's weird for a web based application but it's not my choice :) ). Anyway, it works for Firefox, Chrome and Safari so, too bad for IE.
Thanks!

Output to Chrome console from Node.js

I'm looking for a way to output Node variables directly into the google chrome browser console. The same way a console.log() works on the client side. Something like this for php. This would greatly speed up development.
NOTE:
Since the old answer (written in september 2014) refers to an older version of node-inspector, my instructions are not relevant anymore in 2017. Also, the documentation has gotten a lot better, so I have updated my original answer:
node-inspector is what you need.
It opens up an instance of Chrome with its developer tools for debugging.
It's also easy to use:
1. Install
$ npm install -g node-inspector
2. Start
$ node-debug app.js
Source: https://github.com/node-inspector/node-inspector
You might want to try NodeMonkey - https://github.com/jwarkentin/node-monkey
I know it's an old question but came on top of my Google search so maybe somebody will find my answer useful.
So you can use node --inspect-brk index.js
Now, all you have to do is basically just type chrome://inspect in your Chrome address bar and click Open dedicated DevTools for Node
In DevTools, now connected to Node, you’ll have all the Chrome DevTools features you’re used to:
Complete breakpoint debugging, stepping w/ blackboxing
Source maps for transpiled code
LiveEdit: JavaScript hot-swap evaluation w/ V8
Console evaluation with ES6 feature/object support and custom object formatting
Sampling JavaScript profiler w/ flamechart
Heap snapshot inspection, heap allocation timeline, allocation profiling
Asynchronous stacks for native promises
Hope that helped.
The closest thing to this I've seen is Node JS console object debug inspector
See this post for usage and potential issues: http://thomashunter.name/blog/nodejs-console-object-debug-inspector/
For users with nodejs on linux via ssh-shell (putty):
Problem with nodejs on linux-ssh-shell is, that you have no browser connected.
I tried all this solutions, but didnt get it to work.
So i worked out a solution with firebase (https://firebase.google.com), because my project uses firebase.
If you are familiar with firebase, than this is a great way. If not, firebase is worth using in combination with nodejs - and its free!
In the server-side-script (started with node) use a own function log():
// server-side:
// using new firebase v3 !
var fbRootRef = firebase.database();
var fbConsoleRef = fbRootRef.ref("/console");
var log = function(args) {
fbConsoleRef.set({'obj': args});
}
// inside your server-code:
log({'key':'value'});
On client-side you create a firebase-reference on this console-object:
// client side:
fbRootRef.child('/console').on('value', function(d) {
var v = d.val();
console.log(v);
});
Now everything logged on server-side with the log() - function is transferred in realtime to the firebase-database and from there triggering the client-console-reference and logged into the browsers console.
If anyone needs help, i will explain in more detail and could give a more extended version of this logging with types (console./log/warn/info), grouping with title-info (i.e. server says: (filename + line).
Setting up firebase for your project is done in max 30 minutes, inserting the console-function in 30 minutes. I think its worth the time!
You can use bonsole, a simple way to log something in browser. Even in Linux, you can go to the LAN's ip to check it.
The most simple way with least dependencies is using a WebSocket connection to send the messages to the browser. Any WebSocket example you can find on the internet will suffice to accomplish this. Everything else requires to be heavily integrated into the host system and wouldn't work if you want to actually run this on a remote server. You can also send commands to the server directly from the browser console this way.
Links:
https://www.npmjs.com/package/websocket
https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API/Writing_WebSocket_client_applications

Resources