Exception thrown with adsense on Internet Explorer - javascript

I've copied and pasted inside my HTML tag the adsense javascript code google hands out -
<ins class="adsbygoogle"
style="display:inline-block;width:234px;height:60px"
data-ad-test="on"
data-ad-client="XXXXX"
data-ad-slot="XXXXX"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
[I replaced the actual data-ad-client and data-ad-slot values with XXX when pasting the code here]
It works fine on Chrome, Firefox, Edge but on Internet Explorer i'm getting an exception thrown. It's saying "Javascript runtime error: Unable to get property 'getRandomValues'of undefined or null reference' on the r.crypto.getRandomValues(d); function call within adsense script.
No clue what's going on. Any help is appreciated.

You code be emulating an older version of IE.
You can test for the latest crypto using this script:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Web Cryptography API</title>
</head>
<body>
<script>
var crypto = window.crypto || window.msCrypto;
if (crypto) {
console.log(crypto);
} else {
console.log("Unable to create window.crypto object");
}
</script>
</body>
</html>
You can check the mode you are running in developer tools:

Didn't manage to fully get around it, but i set visual studio to not bother with that exception and everything worked just fine. Eventually switched to DFP so this is no longer an issue if anyone still care.

Related

navigator.locks.request or (LockManager.query) doesn't work in "sandbox" in firefox

The following snippet doesn't work but if you try to paste this in the developer console it will work (in firefox)! This snippet WILL however work in Chrome. (The script will Error because the Mutex times out, that error is however irrelevant)
var controller = new AbortController();
setTimeout(() => {
controller.abort();
console.error(new Error("Mutex timeout"));
}, 3000);
navigator.locks.request("t", {signal: controller.signal}, (lock) => {
console.log(lock);
return new Promise((resolve2) => {
console.log('This will not get logged in firefox.');
window.helpme=resolve2;
});
});
The firefox error is Uncaught (in promise) DOMException: LockManager.request: request() is not allowed in this context.
Why does this work outside the sandbox enviroment, but doesn't work in a sandboxed enviroment like codepen, observablehq or stackoverflow snippets (it seems to work here (firefox included) though)?
I find no firefox documentation about this.
Edit: Okay just found out, in chrome doesn't work with the stackoverflow context, however, it seems to work fine in codepen or jsfiddle (not firefox).
What is going on here?
Edit: Okay, tried to do this without a javascript sandbox, the iframe code is:
<!DOCTYPE html><head></head><body><script>navigator.locks.query().then(console.log).catch(_=>{console.log("Why is this not allowed?");throw _})</script></body>
This code returns a security error in Firefox, and in chrome the LockManager is not available at all... I don't see this documented anywhere.
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div>
<h1>Hello, World!</h1>
<p>Welcome</p>
<iframe src="data:text/html;base64,PCFET0NUWVBFIGh0bWw+PGhlYWQ+PC9oZWFkPjxib2R5PjxzY3JpcHQ+bmF2aWdhdG9yLmxvY2tzLnF1ZXJ5KCkudGhlbihjb25zb2xlLmxvZykuY2F0Y2goXz0+e2NvbnNvbGUubG9nKCJXaHkgaXMgdGhpcyBub3QgYWxsb3dlZD8iKTt0aHJvdyBffSk8L3NjcmlwdD48L2JvZHk+""></iframe>
</div>
</body>
</html>

letter in quotes appearing just after body tag

We've just launched our new Magento site and the letter 'c' is appearing in quotes immediately after the tag. It's not showing up before on my local machine or on our QA site, I've checked the template files and it is not there either. I'm almost certain it can not be a code issue as we have the same code running locally and on our QA site under version control with GIT.
We've cleared the cache and I've tried checking to see if JavaScript was inserting it with the chrome dev tools but could find nothing.
Strangely, the 'c' is not in the view source document but I can see it with the chrome inspector.
I also don't think it can be coming from Magento CMS Pages/Blocks as it loading immediately after the tag.
thanks for the link. after reviewing the page source, you have an extra c character in the header area:
<!-- END GOOGLE ANALYTICS CODE -->
c<script type="text/javascript">//<![CDATA[
var Translator = new Translate([]);
//]]></script>
Notice that c before the script tag?
Just in support to Benny Lin's very helpful answer.
What was happening was we had our Google Analytics code loading from a template file which contained the stray letter 'c'. We could see this on our local machines as this templates was disabled in the Magento admin settings, but not on production.
This issue seems to demonstrate that when a stray letter appears within the <body> tags on your dev tools inspector and not the view source page it may be because it is in the <head> section. The browser seems to push all poorly formatted html from the <head> section into the <body> section when rendering.
For example if you open the below html in the chrome browser you will see what I mean:
<!DOCTYPE html>
<html>
<head>
c<title>Title of the document in head</title>
<script type="text/javascript">
var test = "test";
</script>
</head>
<body>
The body of the document......
</body>
</html>
Also while we were searching for the stray letter, we were ably to remove it with the below JavaScript that targets the offending XML node in the DOM with an XPath expression and removes that node only.
<script type="text/javascript">
function _x(STR_XPATH) {
var xresult = document.evaluate(STR_XPATH, document, null, XPathResult.ANY_TYPE, null);
var xnodes = [];
var xres;
while (xres = xresult.iterateNext()) {
xnodes.push(xres);
}
return xnodes;
}
jQuery(_x('//html/body/text()[contains(.,"c")]')).remove();
</script>

Calling a web service using the script tags

My application is built using asp classic and I've tried multiple solutions trying to fix IE 8's Service is not defined issue. The code is below.
tags:
<script language="javascript">
function init() {
service.useService("Services/Util.asmx?WSDL", "WebUtil");
}
</script>
tags:
<frameset onload="init()" id="service" style="behavior:url(Forms/Behaviors/webservice.htc)" onresult="ShowResult()" border="1" frameborder="1" framespacing="4" cols='<%= GetFrameColString()%>' topmargin="0" leftmargin="0">
Note:
The browser can not be updated due to company policy so it has to work in IE 8 and above. And if there are issues with later browsers when calling a webservice this way would help me out as well if the company decides to upgrade IE.
Anyhow can you help with IE 8's stating "service is not defined" issue?
Solved.
My original code:
<script language="javascript">
function init() {
service.useService("Services/Util.asmx?WSDL", "WebUtil");
}</script>
Modified code:
<script language="javascript">
function init() {
service.useService('Services/Util.asmx?WSDL', 'WebUtil');
}</script>
Apparently it's an syntax error. I assume ASP Classic needs single quotes over double quotes. Right now there is progress in getting my application done.

SERIALITY() plugin installation on firefox or chrome

Please help me to understand how to install the Seriality Plugin (www.zambetti.com/projects/seriality/‎) in Chrome or Firefox.
I want to read from a COM Port on the client side of a web page.
Take a look at the Google code site, this site contains the DMG file you can use to install the Seriality.plugin file.
https://code.google.com/p/seriality/
You can also see the sample source on the site that shows the javascript to use the plugin, below is a snippet shown on the site that prints "Hello World" to the first port seen on the system at a baudrate of 9600 when this HTML file is loaded.
<html>
<head>
<script type="text/javascript">
function setup()
{
var serial = (document.getElementById("seriality")).Seriality();
serial.begin(serial.ports[0], 9600);
serial.write("Hello World");
}
</script>
</head>
<body onload="setup();">
<object type="application/Seriality" id="seriality" width="0" height="0"></object>
</body>
</html>

Javascript image viewer not working in internet explorer

I have made a similar kind of image viewer mentioned in below site for my website.
http://www.javascriptkit.com/script/script2/backbox/
The image viewer is working fine in Chrome but not working in Internet Exlporer;
I have not given my website details for security reasons but you view the issue by copy pasting below link in Chrome and Internet Explorer.
http://www.javascriptkit.com/script/script2/backbox/
Click the Image in above link and see the error in internet explorer & see the same in other browser to see its working condition...
PFB snap shot
Could any one of you tell why is not working in internet explorer ?
Error Msg from IE F12 devolper tools console area is :
SCRIPT5007: Unable to get value of the property 'replace': object is
null or undefined effects.js, line 1 character 1747
effects.js =
http://www.javascriptkit.com/script/script2/backbox/js/effects.js
If you need sample js files, please get that from http://www.javascriptkit.com/script/script2/backbox/backboxfiles.zip
HTML used is;
<link rel="stylesheet" href="backbox.css" type="text/css" />
<script type="text/javascript" src="js/prototype.compressed.js"></script>
<script type="text/javascript" src="js/scriptaculous.js?load=effects"></script>
<script type="text/javascript" src="js/lightbox.js"></script>
<script type="text/javascript" src="js/dhtmlHistory.js"></script>
<script type="text/javascript" src="js/customsignsheader.js"></script>
<div onclick="dhtmlHistory.add('location1',{message: 'backbox'});countdown()">
<a href="images/babyhand.jpg" rel="lightbox[slide]" caption="A Bunch of Grapes">
<img src="images/sunset.jpg" alt="lime" width="400" height="300" border="0" /></a>
</div>
<script type="text/javascript" src="js/customsignsfooter.js"></script>
regarding about your concern why this occurs in IE and not in chrome, that's because of this condition if(/MSIE/.test(navigator.userAgent) which is true when your browser is IE
for correcting the issue, as you said in a comment you can add a 'undefined' condition.
just replace this line:
if(/MSIE/.test(navigator.userAgent)){Element.setStyle(_10,{filter:Element.getStyle(_10,"filter").replace(/alpha\([^\)]*\)/gi,"")+"alpha(opacity="+_11*100+")"});}
with:
if(/MSIE/.test(navigator.userAgent)){var filterStyle=Element.getStyle(_10,"filter");if(typeof(filterStyle)!="undefined"){Element.setStyle(_10,{filter:filterStyle.replace(/alpha\([^\)]*\)/gi,"")+"alpha(opacity="+_11*100+")"});}}
and this line:
if(/MSIE/.test(navigator.userAgent)){Element.setStyle(_10,{filter:Element.getStyle(_10,"filter").replace(/alpha\([^\)]*\)/gi,"")});}
with:
if(/MSIE/.test(navigator.userAgent)){var filterStyle=Element.getStyle(_10,"filter");if(typeof(filterStyle)!="undefined"){Element.setStyle(_10,{filter:filterStyle.replace(/alpha\([^\)]*\)/gi,"")});}}
in the effects.js file
Open developer tools in IE (press F12) and click the "Console" tab. You should be able to see in there that there's an error with the effects.js script :
SCRIPT5007: Unable to get value of the property 'replace': object is null or undefined
effects.js, line 1 character 1747
That should at least give you somewhere to start looking.
...and if you're that lazy, the actual line of code it's failing on is this :
Element.getStyle(_10,"filter").replace(/alpha\([^\)]*\)/gi,"")
The getStyle call is clearly returning null, so subsequently calling replace will fail.
Internet Explorer does not currently have full HTML5 support. Any manipulation of HTML5 related tags or elements will therefore fail. It is worth trying to include the html5shiv library, which tricks IE into believing these tags exist.

Categories

Resources