iframe API continues sending 'postMessage' after iframe src changes - youtube-iframe-api

I have an iframe that is implementing the youtube iframe api. Once I change that iframe src to another video src (non-youtube), the api continues firing postMessage requests to the new origin infinitely.
I've narrowed it down to this chunk of code:
g.C = function(a) {
a.id = this.g;
a.channel = "widget";
a = ab(a);
var b = this.b;
var c = jb(this.a.src);
b = 0 == c.indexOf("https:") ? [c] : b.b ? [c.replace("http:", "https:")] : b.f ? [c] : [c, c.replace("http:", "https:")];
if (!this.a.contentWindow) throw Error("The YouTube player is not attached to the DOM.");
for (c = 0; c < b.length; c++) try {
this.a.contentWindow.postMessage(a, b[c])
} catch (d) {
if (d.name && "SyntaxError" == d.name) ob(d, "WARNING");
else throw d;
} };
That continuously sends this.a.contentWindow.postMessage(a, b[c]) without checking the destination of the contentWindow.
Is there a way to destroy the player once it is no longer needed so this postMessage will not be sent to other sources?
Thanks,
Jake

There is method called player.destroy()
It is documented here : https://developers.google.com/youtube/iframe_api_reference?hl=en#Accessing_and_Modifying_DOM_Nodes

Related

What does the `cx` parameter do in Gtag implementations?

I have been debugging an issue with Google Analytics 4 where when a GA4 property is connected to an existing GA3 gtag property, and the request to fetch the JavaScript from GTM contains the parameter cx=c, the resulting JavaScript does not contain the required child container for GA4.
https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXX-1&l=dataLayer&cx=c
The obvious fix is to remove the cx=c parameter and test, or to use another implementation of GA4 directly, but that is not the question.
After seeing the suggested implementation from Google, (e.g. no cx) and this version (with the cx) passed around in various online discussions, Github code and issues, etc. I am trying to figure out what it does. I have searched all Google docs, searched Github and Stack Overflow. I find it referenced with respect to Firebase, but nothing else. Does anyone know what this parameter does, officially?
Short answer: we have no clue what it does.
Longer answer: as you may know, GTM can deploy gtag. Since it can do that, it has the code for generating that function. Although that code is minified, it can still be useful:
var Fn = function (a, b, c) {
if (!En() && !sg(a)) {
var d = c ? "/gtag/js" : "/gtm.js", e = "?id=" + encodeURIComponent(a) + "&l=" + Cd.ba,
f = 0 === a.indexOf("GTM-");
f || (e += "&cx=c"); var g = Dn();
g && (e += "&sign=" + Cd.Xd);
var l = Bn(b, d + e);
if (!l) {
var m = Cd.uc + d; g && bb && f && (m = bb.replace(/^(?:https?:\/\/)?/i, "").split(/[?#]/)[0]);
l = Ri("https://", "http://", m + e)
} rg().container[a] = !0; hb(l)
}
}
See what it does? f indicates whether there is "GTM-" in a or not. And I didn't look up a, but a must be the fetch url. Now, f becomes a binary representation instead of the -1 returned by the indexOf.
Judging from this code, GTM deploys the cx parameter with a very hardcoded value whenever it deploys something that is not GTM, I imagine, from it's own family of fetch urls, which can include GTM itself. Why GTM doesn't want cx=c for its code? No idea. I have it loaded with it more often than without.
But here's another place where it's used:
Gn = function (a, b) {
var c; if (c = !En()) c = !rg().destination.hasOwnProperty(a); if (c) {
var d = "/gtag/destination?id=" + encodeURIComponent(a) + "&l=" + Cd.ba + "&cx=c";
Dn() && (d += "&sign=" + Cd.Xd); var e = Bn(b, d); e || (e = Ri("https://", "http://", Cd.uc + d)); rg().destination[a] = !0; hb(e)
}
};
En() is always false. It looks like it's some weird remnants from GTM's dev environments. Poor env variables management on GTM's side, but no one cares.
I stopped looking into the Gn function at this point. But if you want to persist digging, you're free to do so. I have a sneaking suspicion that the cx parameter does exactly no difference on the side of the consumer (our side). It may be something beneficial for Google's dev team, but I doubt it. Params, hardcoded like this are rarely a good idea. Looks to me like a fluke.

Robot Framework: Timed out waiting for page load

We have run our Robot Framework environment nearly one year without any problems, but now we get the error message:
TimeoutException: Message: Timed out waiting for page load.
Stacktrace:
at Utils.initWebLoadingListener/< (file:///tmp/tmp77bOby/webdriver-py-profilecopy/extensions/fxdriver#googlecode.com/components/driver-component.js:9089)
at WebLoadingListener/e (file:///tmp/tmp77bOby/webdriver-py-profilecopy/extensions/fxdriver#googlecode.com/components/driver-component.js:5145)
at WebLoadingListener/< (file:///tmp/tmp77bOby/webdriver-py-profilecopy/extensions/fxdriver#googlecode.com/components/driver-component.js:5153)
at fxdriver.Timer.prototype.setTimeout/<.notify (file:///tmp/tmp77bOby/webdriver-py-profilecopy/extensions/fxdriver#googlecode.com/components/driver-component.js:625)
What could be problem? I checked the disk space and there are disk space left.
A timeout error can have a laundry list of possible issues. Loading a page after a year of smooth operation narrows it down a little, but there are still many possibilities. Connection speeds sometimes change, sometimes the page you're loading up has added features that cause it to take longer to load or was just written poorly so it loads slowly... you get the idea. Without the code of the page or your code to look at, I can only suggest two fixes.
First, in the code of Selenium2Library, there is a timeout variable somewhere that can be set with Set Selenium Timeout. The default is 5 seconds, but if your page is taking longer to load, then increasing it might solve your problem. This assumes that your page loads at a reasonable rate in manual testing and that opening it is the least of your concerns.
Second, it's possible that you're testing an AngularJS application, not a normal website. If that's true, then you're going to want to use ExtendedSelenium2Library, not Selenium2Library. ExtendedSelenium2Library is better-equipped to deal with AngularJS applications and includes code to wait for Angular applications to load.
The old webdriver.xpi is buggy about page load handling. Timers are not correctly canceled, resulting in random windows switches and memory leaks. I copy here some replacement code that may be useful to anybody.
var WebLoadingListener = function(a, b, c, d) {
if ("none" == Utils.getPageLoadStrategy()) {
b(!1, !0);
} else {
this.logger = fxdriver.logging.getLogger("fxdriver.WebLoadingListener");
this.loadingListenerTimer = new fxdriver.Timer;
this.browser = a;
var self = this;
var e = function(a, c) {
self.destroy ();
b(a, c);
};
this.handler = buildHandler(a, e, d);
a.addProgressListener(this.handler);
-1 == c && (c = 18E5);
this.loadingListenerTimer.setTimeout(function() {
e(!0);
}, c);
WebLoadingListener.listeners [this.handler] = this;
goog.log.warning(this.logger, "WebLoadingListener created [" + Object.keys (WebLoadingListener.listeners).length + "] " + d.document.location);
}
};
WebLoadingListener.listeners = {};
WebLoadingListener.removeListener = function(a, b) {
if (b.constructor !== WebLoadingListener) {
b = WebLoadingListener.listeners [b];
}
b.destroy ();
};
WebLoadingListener.prototype.destroy = function() {
if (this.browser) {
this.loadingListenerTimer.cancel();
this.browser.removeProgressListener && this.handler && this.browser.removeProgressListener(this.handler);
delete WebLoadingListener.listeners [this.handler]
this.loadingListenerTimer = undefined;
this.browser = undefined;
goog.log.warning(this.logger, "WebLoadingListener destroyed [" + Object.keys (WebLoadingListener.listeners).length + "]");
}
};
enter code here

google map pathRequest not working for polyline

I am working on a website offering a personal list of peaks for mountain lovers.
I am stuck on the function (pathRequest) of a Google map polyline since ages.
I cannot understand as this code is a copy from a lot of sources and a shame Firefox debug is not acting well with the Google map... getting things worst.
Here's the page :
http://www.mes-sommets.fr/ajouter-un-sommet/
To test, you need to enter "adresse départ" (start)and"adresse arrivée" (end) + "manuel"mode in option"itinéraire"`.
Bug is showing when clicking on "adresse arrivée" in autocomplete.
For the two options :
- automatique (google map direction service) -- OK
- manuel (polyline) -- KO
Then I am calling the same functions :
- distance calculation getDistance(path)
- elevation calculation plotElevation(results, status)
Mode automatique (google map direction service) :
var path = result.routes[0].overview_path;
getDistance(path);
Mode manuel (polyline) :
var polyline_path = polyline.getPath();
getDistance(polyline_path);
Function getDistance :
function getDistance(path) {
var m = google.maps.geometry.spherical.computeLength(path);
var km = m / 1000;
document.getElementById("ninja_forms_field_34").value = km.toFixed(2) + " km";
var pathRequest = {
'path': path,
'samples': 256 }
elevator.getElevationAlongPath(pathRequest, plotElevation);
};
Function plotElevation :
function plotElevation(results, status) { if (status ==
google.maps.ElevationStatus.OK) {
var deniv_positif = 0;
var deniv_negatif = 0;
var elev = results[0].elevation;
for (var i = 0; i < results.length; i++) {
if ( (results[i].elevation - elev) > 0 ) {
deniv_positif = deniv_positif + (results[i].elevation - elev);
}
else {
deniv_negatif = deniv_negatif + (results[i].elevation - elev);
}
elev = results[i].elevation;
}
document.getElementById("ninja_forms_field_31").value = "+" + deniv_positif.toFixed(0) + " / " + deniv_negatif.toFixed(0) + " m" ;
} }
Any advice would be great, if I did not put enough code, please tell me. Hope it is OK.
Best regards,
Benjamin
The only thing I can see is this.
The DirectionsRoute overview_path is "an array of LatLngs"
The ElevationService getElevationAlongPath function expects the PathElevationRequest to have an Array for its path.
All good so far...
However, the Polyline getPath function returns an MVCArray, not just an Array.
Usually they seem pretty interchangeable to me, but this might be one place where they're not.
You could try calling the getArray function on the MVCArray to convert it into an Array and see if that makes any difference.
var polyline_path = polyline.getPath();
getDistance(polyline_path.getArray());

Unsufficient privileges from responseText in Plone4.3

I use PloneBooking3.0.0a2 with Plone4.3.3, but if I want to show periodic bookings I get an unsufficient privileges error. In my opinion there are two functions responsible for that:
function showPeriodicityResult(url, alt_url, target_id, form_id, waiting_text) {
ajaxobject = getXmlHttpRequest();
form = document.getElementById(form_id);
periodicity_type = getPeriodicityType(form);
periodicity_end_date = form['periodicity_form_periodicity_end_date_0'].value;
periodicity_variable = form['periodicity2_x'].value;
query = getPeriodicityQuery(periodicity_type, periodicity_end_date, periodicity_variable);
url = url + query + "&d=" + (new Date()).getTime();
alt_url = alt_url + query;
// Opera does not support ajax
if (ajaxobject == null) {
window.location = alt_url;
} else {
var node = document.getElementById(target_id);
node.innerHTML = waiting_text;
ajaxobject.open('GET', url, true);
ajaxobject.onreadystatechange = function(){CallBackGenerateAjaxHTML(ajaxobject, target_id);};
ajaxobject.send(null);
}
}
and
function CallBackGenerateAjaxHTML(ajaxobject, target_id) {
if (ajaxobject.readyState == 4) {
if (ajaxobject.status > 299 || ajaxobject.status < 200) {
return;
}
elem = document.getElementById(target_id);
elem.innerHTML = ajaxobject.responseText;
}
}
Especially the innerHTML setting with responseText seems to be a problem. Is there is a quick answer like Plone version diff from 3 to 4 or must I work in-depth?
You mentioned in the comments that the portal.uid_catalog raises the Unauthorized.
When I recall correctly the uid-catalog requires a higher permission since the last Plone hotfix. But you also can search an Item when given a UID with the normal Catalog.
here_obj python:portal.portal_catalog(UID=here_uid)[0].getObject();
This way you should be able to get your Object.

Asp.net paging crashing on chrome

I have a timer control on my page and an image handler which is set on every timer refresh. After about two minutes of running my page the page crashes on chrome with the "Aw Snap message". Can anybody help me out ??
JS Code.
var t
function set_coordinates_up(event) {
//Get final co-ordinates
var pos_x = event.offsetX ? (event.offsetX) : event.pageX - document.getElementById("divCar").offsetLeft;
var pos_y = event.offsetY ? (event.offsetY) : event.pageY - document.getElementById("divCar").offsetTop;
var hdf = document.getElementById('HiddenField1')
//Store event information in hidden feild
if (hdf != null) hdf.value = t + " " + pos_x + " " + pos_y;
}
function set_coordinates_down(event) {
//Get initial co-ordinates
var pos_x = event.offsetX ? (event.offsetX) : event.pageX - document.getElementById("divCar").offsetLeft;
var pos_y = event.offsetY ? (event.offsetY) : event.pageY - document.getElementById("divCar").offsetTop;
t = pos_x + " " + pos_y
}
check if your tab is leaking memory for some reason by opening up Chromes Task manager... probable reasons would be an infinite loop somewhere.
Chrome pages usually crash (Snap!) when there is low memory on the system. I would worry about that too.. Make sure you dont have many other processes running either.
Keep us updated.

Resources