CefSharp and frames, only retrieving HTML from first frame - html

pcpao.org/general.php?strap=152814186280001650
In trying to get the full HTML from that site, .GetSourceAsync and .ViewSource, both only show the 'frameset' HTML. Using the ShowDevTools option, the full HTML data is in both the elements collection and the Sources of the Chrome-devtools.
I am running this after the webpage has loaded, but it should all be there still since its in the dev-tools?
What am I missing to get the full HTML out of a navigated site. I suspect this has to do with frames but after an hour of googling and reading old messages I see this only tangentially mentioned.
Winforms
package id="cef.redist.x64" version="3.2526.1362" targetFramework="net46"
package id="cef.redist.x86" version="3.2526.1362" targetFramework="net46"
package id="CefSharp.Common" version="47.0.3" targetFramework="net46"
package id="CefSharp.WinForms" version="47.0.3" targetFramework="net46"

I was having the same issue trying to get click on and item located in a frame and not on the main frame. Using the example in your answer, I wrote the following extension method:
public static IFrame GetFrame(this ChromiumWebBrowser browser, string FrameName)
{
IFrame frame = null;
var identifiers = browser.GetBrowser().GetFrameIdentifiers();
foreach (var i in identifiers)
{
frame = browser.GetBrowser().GetFrame(i);
if (frame.Name == FrameName)
return frame;
}
return null;
}
If you have a "using" on your form for the module that contains this method you can do something like:
var frame = browser.GetFrame("nameofframe");
if (frame != null)
frame.EvaluateScriptAsync("document.getElementById('whateveridyouwanttoclick').click();");
Of course you need to make sure the page load is complete before using this, but I plan to use it a lot. Hope it helps!

Thanks, some examples from previous versions had me confused how this works. I was looking for something like this.
var frameIdent = Browser.GetBrowser().GetFrameIdentifiers();
var result = Browser.GetBrowser().GetFrame(frameIdent.Last()).GetSourceAsync().Result;
textBox1.Text = result.ToString();
So I guess the way to get all HTML from a site is loop through the frames identifiers list, get the result from each frame via GetSourceAsync and concatenate them all to a string.

Related

Game assets not loading in Kongregate

I just created my first game, and am having some problems. I uploaded to Kongregate(but didn't publish yet), and in the preview the external files(music and three pictures) don't load. The rest of the game works fine.
If I try to change it so there is a zip with the assets in it and change the directory in the code, it falls apart.
I'm using FlashDevelop, so everything is programatic. I noticed the swf is only a few kb large, so is there anyway to compile the assets into the swf file and load them that way, or do I need to do something else?
Please help, and thanks in advance.
Ok, let me explain then. Lets assume you have your main module game.swf that loads some image asset.jpg from the same folder. You test it locally, it works just fine. You put game.html, game.swf and asset.jpg on your site http://niamke.com/ and it still works. Then you publish your game as http://kongregate.com/games/niamke/myniamkegame/ and it suddenly stops loading asset.jpg.
Why
HTTP requests from Flash Player are handled via browser. So the browser gets a request for "asset.jpg" from Flash Plugin instance. There could be all kinds of content (including several Flash Apps) from several different domains within one page, so browser does not bother to figure the correct address out, and plainly tries to load in relatively to the topmost HTML document, basically http://kongregate.com/games/niamke/myniamkegame/asset.jpg which is not there.
How to avoid it
You should create a small piece of code that figures the correct URLs for the files you load. As soon as your content attached to Stage, any display object can access the loaderInfo object which contains the absolute SWF URL.
Usage
Files.parseURL(loaderInfo.url);
var aLoader:Loader = new Loader;
var aRequest:URLRequest = new URLRequest(Files.baseUrl + "asset.jpg");
Loader.load(aRequest);
Implementation
package
{
public class Files
{
// Long live Bill Gates and Windows and backslashes.
static public function figureSlash(value:String):String
{
var aSplit:Array = value.split("/");
var oSplit:Array = value.split("\\");
return (aSplit.length >= oSplit.length)? "/": "\\";
}
static public var baseUrl:String;
static public var systemSlash:String;
// Supposed to dissect the SWF url in order to
// process relative resource file urls properly.
static public function parseURL(value:String):void
{
// Figure correct slash.
systemSlash = figureSlash(value);
// Split SWF URL into Array and remove SWF name.
var aSplit:Array = value.split(systemSlash);
aSplit[aSplit.length - 1] = "";
// Obtain the SWF root folder.
baseUrl = aSplit.join(systemSlash);
}
}
}
A comment brought me to the conclusion below:
"I just linked the URLRequest to where the files were hosted online."

display only a specific content in AS3 code using webStage View

I'd like to display, in my app, only a part of a web page.
On this website, I'd like to display, in my app, only the div id "MovieCart".
What should I write in my as3 code in order to do so ?
For now, I have this line :
webView.loadURL("http://www.cinecity.nc/Cinecity/Film/40565");
But, of course, it's displaying the fullwebpage.
EDIT
So, I've tried this :
webView.addEventListener(Event.COMPLETE,onComplete);
var res : String = ExternalInterface.call("function(){return document.getElementById('movieCart').outerHTML}");
var urlOfMovie: URLRequest = new URLRequest("http://www.cinecity.nc/Cinecity/Film/40567");
var loaderMovie:URLLoader = new URLLoader();
loaderMovie.load(urlOfMovie);
webView.loadString(res);
But, as it's an AIR app, ExternalInterface.call can't be call. Any idea ?
Here is one easy way you can accomplish this:
//First, load the full page as you're currently doing:
webView.addEventListener(Event.COMPLETE, webLoadComplete); //listen for when the load is finished
webView.loadURL("http://www.cinecity.nc/Cinecity/Film/40565");
//runs when the load finishes
function webLoadComplete(e:Event):void {
webView.removeEventListener(Event.COMPLETE, webLoadComplete); //stop listening
//second, invoke the following Javascript on the page which assigns the `MovieCart` element as the html for the whole document body
webView.loadURL("javascript:document.body.innerHTML = document.getElementById("MovieCart").outerHTML");
}
Disclaimer:
Keep in mind that scrapping content from websites is generally frowned upon and you may be infringing on peoples work/copyrights by doing so.

AS3 POST png to PHP

Have read many similar but no solutions: I'm trying to do something (that i think is) really simple,
Take a photo from gallery or camera - and POST this to a URL. No saving / returning to application. The PNG is just used by the webpage in display and user moves onward.
public function postPicture():void {
PNGEncoder2.level = CompressionLevel.FAST;
var encoder : PNGEncoder2 = PNGEncoder2.encodeAsync(_bitmapData);
encoder.targetFPS = 12;
encoder.addEventListener(Event.COMPLETE, function (e):void {
var png : ByteArray = encoder.png;
var header:URLRequestHeader = new URLRequestHeader("Content-type", "application/octet-stream");
var jpgURLRequest:URLRequest = new URLRequest("https://myurl.com/mypage");
jpgURLRequest.requestHeaders.push(header);
jpgURLRequest.method = URLRequestMethod.POST;
jpgURLRequest.data = png;
navigateToURL(jpgURLRequest, "_blank");
});
}
Also to note, we're getting some odd characters on the end of the URL: C9%90NG
Hunch is that I'm decoding and then not encoding properly before sending i.e. these characters some part of raw image info.
When I test from chrome POST extension with another image, server side stuff works fine so guessing a problem with AS3.
basically its working when I use chrome to browse > my.png and POST it at the page. Am I missing something with the AS3 png encoder? i.e. how to turn that bmpdata into a 'file' rather than an array of bytes.
thankyou
You need to use multipart upload. It's a common situation with a well defined standards for that. You can implement it by yourself but it will take some time and efforts.
What I've used before is the Multipart URLLoader Class provided by Eugene Zatepyakin, one the best Flash guru's out there :)
It's some kind of old but does the job extremely well. You can add variables, files, whatever content you want to your loader and simply submit it. There are examples with the php side of the thing so you can understand what's going on.

Global Variables in Chrome Extensions

Is there a simple way where I can access a global javascript variable through content-scripts in chrome extensions?
Accessing global object from content script in chrome extension
I followed the steps mentioned in the above link, but it did not work out for me. Any help would be much appreciated.
Thanks,
Shankar
I managed to complete it. Thanks for the help. I used simple message passing to retrieve the value from the extension script to the content script. The place where I had missed was, the listener at the extension script needs to be at the background page (I think so). Once I changed that, it worked.
For those from the future looking for an answer to this question, here's how I do it:
function getVariable(v) {
var c = document.createElement("div");
c.id = 'var-data';
c.style.display = 'none';
document.body.appendChild(c);
var s = document.createElement('script');
s.innerHTML = 'document.getElementById("var-data").innerText=JSON.stringify('+v+');';
document.head.appendChild(s);
var data = JSON.parse(c.innerText);
c.remove();
s.remove();
return data;
}
And basic usage:
getVariable('globalVarIWantToAccess');
All this script goes in the content-script, not the code for the main webpage, which means that no co-operation is needed from the webpage itself. Basically, the getVariable function creates a script element which is injected into the main page. This script tag retrieves the requested global variable and puts the data into a new div. The function then gets this data from the new div, deletes the new div, deletes the new script element and returns the data.

Flash HTML image link AS3

I have a flash as3 file, and I'm importing an HTML file that contains this link:
<img src="https://www.paypal.com/en_GB/i/btn/btn_buynowCC_LG.gif" id="paypal_button">
and I cannot for the life of me figure it out, I've looked everywhere.
There were a couple of forums that suggested:
function onTicketLoad():void {
if(paypal != null && this.contains(paypal)) {
removeChild(paypal);
}
var imgLoader:DisplayObject = content_text.getImageReference("paypal_button");
//imgLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,onHtmlImageLoaded);
paypal.addChild(imgLoader.content);
}
function onHtmlImageLoaded(e:Event):void {
e.target.removeEventListener(Event.COMPLETE, onHtmlImageLoaded);
paypal.addChild(e.target.content);
paypal.buttonMode = true;
paypal.useHandCursor = true;
addChild(paypal);
}
(that example is fragmented as all hell, I just included it to illustrate what I'm trying to do)
Basically I think I need to load the image into the getImageReference method... but I'm so lost... any help would be appreciated!
I've found creating links on <img> tags in TextFields in Flash can be problematic.
I spotted the issue has been reported on the adobe bug tracker here:
http://bugs.adobe.com/jira/browse/FP-2146
Once as a workaround I created a separate swf file the exact same size as the image and embedded that instead (i.e. a 160x47 stage and a MovieClip/button with a clickable link using navigateToURL). Basically you can embed swf files within TextFields the same way as images.
It's not ideal but it did seem like a decent compromise considering the swf 'button' can now be used and laid out in more or less the same way as you would have used the <img> tag.
If you are going to use the < img > tag in an htmlText box, "you must set the text field to be multiline and to wrap text"
I tried it, and it works fine for me. It loaded the image and the link worked too. Here is my code:
import flash.text.TextField;
var labelText:String = '<img src="https://www.paypal.com/en_GB/i/btn/btn_buynowCC_LG.gif" id="paypal_button">';
var label:TextField = new TextField();
label.border = true;
label.multiline = true;
label.wordWrap = true;
label.width = 200;
label.height = 100;
addChild(label);
label.htmlText = labelText;
My example uses pure AS3, but it should be exactly the same as selecting "multiline" and "wordwrap" from your textfields properties panel.
AIR (Mobile) ignores IMG tags for security apparently... useless in my opinion.
Adding the fact the TextFlow is not recommend or supported for that either in Mobile, and many other fruit less attempts to get an IMG tag to render is beyond challenging so far. I'll wager nearly impossible with the given components (in AIR Mobile land of course, which is not well documented and conflictive with online sources around the issues, so it is unclear and confusing being fresh out of beta).