I am trying to write a PAC file which can read a Windows Environment Variable that is set by GPO (e.g. ENABLE_PROXY = FALSE/TRUE)
Based on whether this Variable is true or not will either return a correct proxy server (uk-proxy-01:80) or a localhost (localhost:80)
I have read references online that say a PAC file is just javascript code. My google searching hasn't returned anything that works.
All I essentially want is:
if ( ENABLE_PROXY == "TRUE" ){
return "PROXY uk-proxy-01:80";
else }
return "PROXY 127.0.0.1:80";
{
You will need to read the environmental variable:
var result = WScript.CreateObject("WScript.Shell").Environment("SYSTEM")("ENABLE_PROXY");
if (result === "TRUE") {
...
Related
I'm trying to catch console logs of an iframe which I don't have access to its source and its implementation.
<iframe src="an http address" name="my-iframe" allowFullScreen/>
When the iframe logs data I see them in my console. But the problem is,
this piece of code
// define a new console
var console = (function(oldCons){
return {
log: function(text){
oldCons.log(text);
if(text === "hi"){
alert("text")
}
},
info: function (text) {
oldCons.info(text);
if(text === "hi"){
alert("text")
}
},
warn: function (text) {
oldCons.warn(text);
if(text === "hi"){
alert("text")
}
},
error: function (text) {
oldCons.error(text);
if(text === "hi"){
alert("text")
}
}
};
}(window.console));
//Then redefine the old console
window.console = console;
Which I got from this post is not working for the iframe logs. It only works on my app console logs.
If the src is a different domain, and you can't run code directly on the other domain (for example, by being able to modify or insert a .js into it), then there's nothing you can do. This is for security reasons: browsers don't want to leak any information between domains unless the sender of the information deliberately allows it.
If you can alter code on the other domain, you could monkeypatch the console and have it pass the log information to the parent window with postMessage so that the parent can do something with it.
If you happen to be trying to examine messages for your personal use only (rather than for use by random people on the internet), you can modify your browser to run your custom JavaScript on the other domain with a userscript, by using a userscript manager like Tampermonkey.
I am working on a web site using angularJS. The project is made on Visual Studio so the server is IIS.
When using Chrome, everything is working fine. But my boss wants also this site to work fine with Internet Explorer 11, in case of some clients are only using this browser.
The problem is that i have an error at an unexpected place when is use IE, for example :
Syntax Error : Caractère Incorrect ( that's french, it means Invalid character )
at getConnectedUser (http://localhost:54579/mypath/myfile.js:121:13)*
And if i open this file at line 121
vm.connectedUser = JSON.parse($cookies.get("userLogged"))
and the 13th character is the v from vm ( since i have some tabs )
the wole function is :
function getConnectedUser() {
vm.connectedUser = JSON.parse($cookies.get("userLogged"))
}
Which is quite normal according to me...
I don't know how to solve this, since the error does not seem to come from the code but from the interpretation of my browser.
I have read that some keywords were not supported to declare variables, like const. I use "let" to declare my variables and it is supported by IE 11 according to this site
EDIT : i also use "var" ( for example : var vm = this )
It would be very helpful if you have some ideas to find a solution.
Thanks for reading,
Sonny
So
I tried to apply what you guys asked, here is what i've got :
The problem actually comes from my cookies, IE can't read it correctly, I get undefined when trying to log my cookie's type, instead of getting "string".
So i went to a different part of the projet, where this cookie is created.
I try to log the cookie just after it is created so it can't be alterated:
var myObject = { "value" : "sonny" }
var stringified = JSON.stringify(myObject) // myObject is validated by jsonlint.com
try {
$cookies.put("userLogged", stringified, {})
console.log("ok")
}
catch (error) {
console.log(error)
}
// i got "ok" in logs , the try part is successful
console.log("fresh cookie : ")
console.log(typeof $cookies.get("userLogged"))
// On Chrome Console : string
// On Ie Console : undefined
console.log(typeof JSON.parse($cookies.get("userLogged")))
// On Chrome Console : object
// On Ie Console: Not logged , i have the Syntax Error Message
So the problem seems to be that IE can't read the cookie i just set before.
Using IE developers tools , i can see the cookie line :
Value : %7B%22value%22%3A%22sonny%22%7D
each special character ( '{', '"' and '}' ) is replaced by "%7B" , "%22" and "%7D"... It is exactly the same with chrome developers tools so i don't think it should be a problem.
Can IE actually read cookies using angular and ngCookies ?
As everyone mentioned in comments.
It is difficult to solve the issue with information provided.
So the best option could be using IE developer tools and debug your application.
Here is how I can troubleshoot the issue.
function getConnectedUser() {
// forces browser to stop at below line
debugger;
var loginInfo = $cookies.get("userLogged"); //put a debug point
// check for loginInfo existence and typeof loginInfo should be string
if (loginInfo && typeof loginInfo === 'string'){
vm.connectedUser = JSON.parse(loginInfo);
}
}
Put a break point in the getConnectedUser function
Check the value of $cookies.get("userLogged"), whether it is returning data or not
yes => check the type of data. It must be a valid JSON string format.
No => do the corresponding actions
I'm using localStorage in my JS application and I was wondering why IE9 claims localStorage == undefined. As far as I know, IE8 supports it, is here any way to get it working in the new version?
Are you testing this on a local HTML file? i.e. a file:/// URL?
localStorage is only available on HTTP websites. That hasn't changed in IE9 Dev Preview.
IE 11 WORKS
All you need two do add file://127.0.0.1 to the trusted zones under the security
tab (NOTE: make sure https check box IS not checked)
add this line to the top or your script, depending on your code you may not need to unless you get could not connect to the internet.
!localStorage && (l = location, p = l.pathname.replace(/(^..)(:)/, "$1$$"), (l.href = l.protocol + "//127.0.0.1" + p));
if (typeof(Storage) != "undefined") {
// Store
localStorage.setItem("lastname", "Smith");
// Retrieve
alert(localStorage.getItem("lastname"));
} else {
alert("Sorry, your browser does not support Web Storage...");
}
Try to open the file like this
file://127.0.0.1/c$/pathtofile/file.html
I'm using Chrome, and I want monitor brower access log for myself ( I suspect some extension send url in background, etc ), I try to use Privoxy, but it can't logging HTTPS url
I think PAC is the only way for logging original url, I use PAC for few years, but I still don't know how to debug it or logging access. How I can do it ? (or any way to logging original url)
I guess some code:
function FindProxyForURL(url, host) {
/*
logging variable 'url' there, but how to write it to file or somewhere ?
// some logging code
*/
if (0
|| shExpMatch(url, "*facebook*")
|| shExpMatch(url, "*google.com/*")
|| shExpMatch(url, "*twitter/*")
) {
return "SOCKS5 127.0.0.1:55777; SOCKS5 127.0.0.1:55888";
}
return "DIRECT";
}
Whenever I try to run a '.js' file in SciTE (Scintilla Text Editor) I almost always get an error stating that certain variables are undefined. I'm guessing that SciTE doesn't have many JavaScript libraries, but I'm not sure.
A few searches yielded me these two blog posts on how to get SciTE to print JavaScript test to its output, rather than just opening a web browser when you press F5 to test the code.
I tried them both, but I either got the same errors as before with the first post's solution, or I got an error that said "'jrunscript' is not recognized as an internal or external command, operable program or batch file" with the second method.
So, is it possible to test JavaScript code in SciTE and print the JavaScript output (or errors) to SciTE's output?
Simple example code I've tried:
console.log("test")
The error message I received for this: 'Microsoft JScript runtime error: 'console' is undefined'
What is SciTe?
SciTE is a SCIntilla based Text Editor. Lua is embedded with SciTe which allows you to access the Scintilla API.
# lua code example
`command.go.*.js=jrunscript $(FileNameExt)`
How to run js code in SciTe?
Create a file called testConsole.js with the following content.
var console = console || {};
console.log = ( console.log || function( str ){
if( typeof print == "function" ){
print( "LOG: " + str + "\n" );
}
return "LOG: " + str;
});
console.log( "Javascript works." );
Open testConsole.js in SciTe.
To run the code, press F5 or click Tools > Go.
An output window should appear showing
LOG: Javascript works.
How do I configure SciTe to run javascript?
I'm using SciTe 3.2.0. Located here
In wscite\wsite320\cpp.properties at line: 424
change:
command.go.*.js=cscript /nologo $(FileNameExt)
to:
command.go.*.js=jrunscript $(FileNameExt)
if you want to use node.js, then change it to
command.go.*.js=node $(FileNameExt)
Make sure that you have the jrunscript or node in your path for the environment variables.
Tutorial here
Do I have jrunscript?
Here's the easiest way to check.
Open up run > type in cmd > type jrunscript.
js> should appear on the screen.
jrunscript.exe should be located here.
C:\Program Files\Java\jdk1.7.0_01\bin\jrunscript.exe
Download the lastest Java SDK if you can't find it.
Error Messages
What does 'Microsoft JScript runtime error: 'console' is undefined'
This means Microsoft JScript ran your javascript and couldn't find the variable console.
Define console to get rid of the error message.
var console = console || {};
console.log = ( console.log || function( str ){
if( typeof print == "function" ){
print( "LOG: " + str + "\n" );
}
return "LOG: " + str;
});
Microsoft JScript might be located here:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\jsc.exe
Error: Input Error: There is no file extension in "location"
Solution: You need to configure the cpp.properties file for javascript.
Error: script file test is not found
Solution: Rename the file. Make sure that it doesn't have any spaces.