Chrome Extension: Communication iframe <-> Content Script - iframe

Well, a often discussed thing. But I can't get it work. What has to be done:
The Content or Background Script has to communicate with the iframe et vice versa.
The iframe is under my hand, so there is everything possible.
I tried a lot. It doesn't work at all. For instance: If I deploy the content script on every page with allFrames=true via (manifest). Ok, makes sense. The iframe is created later so the trigger won't be called. So let's do this: create the iframe and afterwards sending an executeScript request:
chrome.tabs.executeScript(tabinst.tab_id, { allFrames: true, file:'frame.js'}, function() {
console.log("done");
});
But that doesn't work either. Has anyone a solution to communicate with an XDM iframe and a chrome extension?
PS: How nice it would be if the chrome extension would allow postMessage on iframe
EDIT1:
The code doesn't get injected in the iframe. Scenario:
The file "file.js" has a simple foo function in it. I now apply it with the above statement 2 seconds after the iframe was created and showed. This function foo is not available in the iframe...but is in the content script. The ReferenceError is thrown by trying to execute foo within the iframe (by click).
So, it's not a timing thing. And it doesn't matter if I apply the Scripts via manifest and all_frames true. If that would work, the content_script would be available. But is not.
EDIT2:
#serg
Yeah, thanks, that works! I just got through it. My problem was, that I assumed that when the callback of chrome.tabs.executeScript is called, the requested script is ended and the including DOM manipulation finished. But that's actually not the case. It takes some time till the script in the iframe and the containing listener is ready.
So I had to send a chrome.extension.sendRequest from that script in the iframe and then start some code out of the background listener to manipulate the iframe. Thanks for your help.
PS: It's also possible to do it without "all_frames": true. It just takes some time till the dynamic iframe is ready. With a timeout it works. For the most cases, this is not useful, but maybe someone has another user interaction first.
PPS: I still can't see why it's possible like this, and not possible to send postMessage events. But maybe somewhen this will works.

I just tested and content script is getting injected into dynamically created iframes (I used manifest). I think the problem is you are trying to access content script's function within iframe, which is not allowed.
Inside your iframe you can't just do:
<a onclick="contentScriptFunction()"></a>
You need to be adding event listener from within the content script:
$("a").click(contentScriptFunction);

Related

Codeceptjs doesn't load most elements, waitForNavigation() just causes it to freeze forever

I am having an issue testing with codeceptjs. I am attempting testing apps on the Atlassian cloud but codeceptjs/puppeteer cannot interact with any of the elements on the page. When I enable screenshots I see it is on the right page but codeceptjs can only find the elements in the navigation menu. it cannot even find the body element either by selector or xpath.
I tried adding I.waitForNavigation() but the tests never advance past that step. I tried to set a timeout in the config section as they say in the docs here but I am having no luck. I tried everything they suggested but it just waits there forever. if I comment out I.waitForNavigation() it will fail because it cannot find a Boyd element. I am using the default config file that gets created when you install codeceptjs in a directory. this the code I am trying to test but it is causing all kinds of issues.
I.amOnPage('https://artemis-test2.atlassian.net/wiki/plugins/servlet/ac/com.nurago.confluence.plugins.treecopy/copy-page-tree-confluence?page.id=25821196&space.key=TEST1');
I.waitForNavigation();
// if I don't comment this out it will wait here forever
I.wait(4);
I.waitForElement('.ap-iframe');
// it can find the iframe for some reason but nothing else
I.waitForElement('.body');
// if I do comment it out it fails here because it says there is no body element. can't find it by xpath either.
I have no idea why this is happening. any help is greatly appreciated.
amOnPage with default config runs navigation and passes after navigation.
waitForNavigation will start to wait navigation after navigation. So it never happens, if you will not run navigation again or page redirect starts.
You have 2 choices:
not to use waitForNavigation and use amOnPage only.
use waitForNavigation and amOnPage within Promise.all: await Promise.all(I.waitForNavigation(); I.amOnPage(pageUrl));

Adobe tag manager - Direct Call Routes - Direct call rule "DCTEST" not found

Just wanted to know if anyone has ever seen this error when setting up Adobe Tag Manager Direct Call Routes. Direct call rule "DCTEST" not found.
I've logged created a new direct call rule named it DC TEST
In the conditions section named it DCTEST
In Adobe Analytic selected -> s.t(); - increment a pageview
Then in Javascript selected Non-Sequential and created a javascript script and added
window.alert("DC Fired")
Then in my localhost called
_satellite.track("DCTEST");
I get the error:
SATELLITE: Direct call Rule "DCTEST" not found
Event based tracking works and datalayer is populated as expected but when creating a direct call rule it doesn't seem to find what I've set up?
Followed the adobe video but still no luck?
https://outv.omniture.com/?v=tvaTY4ZzoJ087ioJpJptl9npM_8QGDxU
Any ideas?
Can anyone get the video to tutorial to work?
https://outv.omniture.com/?v=tvaTY4ZzoJ087ioJpJptl9npM_8QGDxU
Thanks
That error message is output when
a) The direct call rule doesn't exist
b) The direct call rule isn't published and you are in published/live mode (which is effectively the same thing as (a), in principle)
If you are using the production tag, you can put it into staging/debug mode by entering the following into your js console:
localStorage.setItem('sdsat_stagingLibrary',true);_satellite.setDebug(true);location.reload();
You can make a browser bookmark out of it like so:
javascript:try{localStorage.setItem('sdsat_stagingLibrary',true);_satellite.setDebug(true);location.reload();}catch(e){}
Then you can just press a bookmark button to put it into staging/debug mode.
Also there is an Adobe DTM Switch browser plugin which basically does the same thing (though it doesn't reload the page when you flip switches, so you still have to do that for it to take effect).

The nature of JS Bin

Can someone explain why awesome tools like JS Bin give errors like:
Runner: Permission denied to access property 'scrollX'
when I'm trying code like:
<button onClick="exit();">Exit</button>
<script>
function exit() {
window.location = 'http://www.youtube.com/';
}
</script>
...that work fine if they are called from a regular file in the browser?
Thanks.
Edit: Correction Firefox gives the error.
It's because the iframe that the runner (the thing that automatically generates the preview in jsbin) has sandbox'ed properties on it.
It's been set up so that the only thing that the iframe can't do is set the location of the window. This stops someone from sending a malicious bin to another user, and then suddenly redirectly elsewhere.
Similarly, sites like youtube.com prevent their content from being set in an iframe, and such you see a blank window, like this: http://responsivepx.com/?youtube.com (note that the blank window is where youtube.com is supposed to be).
I'm the primary dev on jsbin by the way, which is why I know :)

How do I tell when GroundOverlays in kml have finished loading?

I'm doing this:
google.earth.fetchKml(ge, slopehref, function(kmlObject){
if (kmlObject){
ge.getFeatures().appendChild(kmlObject);
// GroundOverlay's still not rendered
}
});
So I know when the kml file is loaded but then it takes a few seconds to load the GroundOverlays. I want to get a callback when the GroundOverlays have rendered. I have been looking for google.earth.addEventListener eventids that might fire when network activity has stopped but I can't find anything about it.
Unfortunately this is not possible, there is no way to do this in the current Api. The best you could do is to put a feature request in for this functionality to be added:
http://code.google.com/p/earth-api-samples/issues/list
There is a similar request already in there as well if you wanted to 'star' it:
http://code.google.com/p/earth-api-samples/issues/detail?id=5

Why is my javascript function not found by the page it is embedded in?

I have a page that has a simple javascript in the header portion of the page:
<script type="text/javascript">
function doLogout() {
var conf = confirm("Really log out?");
if (conf === true) { //changed == to === for boolean comparison
$.post("logout.aspx");
}
}
</script>
It uses jQuery to do an AJAX post to my logout page. The only issue right now is that when I click on the link (logout) to fire this function, nothing happens. I checked FireBug's console, and it told me that the function is not defined. This has happened to me before, but I think I botched a bunch of code to fix it sometimes.
Does anyone know the proper way to fix this issue?
Edit
After doing a lot of googling and trying different things, I found this very concise and informative post. Apparently, as the linked article states, the way the script is referenced in the web site is important as it won't run properly otherwise! Hopefully this information will be useful for more people.
This can also occur if there is a syntax error earlier in your javascript code. Often this will just be interpreted as the function not existing (nor any function AFTER the error). Check the code above this code (if there is any) and this code for syntax errors.
A way to tell if the cache error is it is to open Firebug and view the Script source. If the page was cached, you won't see your code. If it loaded but has syntax errors, the code will show, though it won't "find" it.
Things to test:
1) Can you call this function from something else? Like add a <script> at the bottom of the page to call it?
2) Does the page validate? Sometimes I get screwy javascript errors if there is some busted HTML like a missing </b>
3) I've been starting to wrap my javascript in <![CDATA[ ]]> just incase I've got goofy chars in my javascript.
4) I assume you've tested this in other browsers and have the same behavior, right?
5) If you haven't installed it already, install the Web Developer firefox addon. It has a nifty toolbar menu that will disable the cache for you so everything reloads.
6) As weird as it sounds, I once hit a javascript issue that was because of how my text editor was saving UTF-8 files. I forget the details, but it was adding some byte-order-mark or something that upset the browser.
I've had this occur when the page had been cached and so it didn't load the new script in. So to fix it clear all private data from Firefox. Not sure if that helps but it sure happened to me a bunch.
Other ideas for you to test:
is the function defined in the DOM tab in FireBug?
if you call doLogout() from the FireBug console, what happens?
I assume this is not the only script on that page. Make sure that some later script is not modifying doLogout to something else
I had the same issue and tried all that's been suggested here without success.
The only way I fixed it was by discovering that in the <script src="jquery.js"> tag I was using in the head of the page I forgot to close it with its </script> causing the page to ignore all Javascript functions. So please check that your includes look like:
<script src="jquery.js"></script>
I hope that helps. Ross.
If you are using DevExpress controls these links may help you: How to register and execute a JavaScript downloaded to the client via a callback and How to register and execute a JavaScript downloaded to the client via a callback (standalone JS file) and Executing javascripts from user controls dynamically created through ASPxCallback panels
The issue might occur if you have NoScript. You should check and make sure it's not blocking said script.
I had this issue and discovered the problem was just a wrong case letter inside the name.
Call: filterCheckbox()
vs
function filterCheckBox() {}
problem: lowercase "box" vs uppercase "Box".
So check if the name is exactly the same.

Resources