What is the awesomium navigate code? - basic

What I am asking is what is the code to get the Awesomium web frame element to load specific pages? For example, the default Microsoft WebBrowser Element uses WebBrowser.Navigate(variable). What is the Awesomium equivelant of this?

If your requirement is to simply load a given URL and grab the final/rendered HTML source of that page, check out this sample console app project on github.
It has a class called Browser which is a simplified thread-safe wrapper class for using Awesomium like the WebBrowser control but in a headless/windowless environment. Shouldn't be that difficult to modify it for a UI environment.
You can use that class like so:
Browser.StartWebCore()
Dim B as new Browser()
Dim HTML as String = B.GetRenderedHTML("http://cnn.com")
B.Dispose()
Browser.StopWebCore()

Related

Load HTML file and display in Flutter Web

I have a single HTML file that contains some JS functions and CSS styling.
Is it possible to load my html file into an embedded widget on Flutter Web? I've successfully accomplished this on iOS and Android using the flutter_webview pacakge, but haven't found a solution for Flutter Web.
There is a HTMLElementView widget which can help you embed Html in flutter web. This widget can take an Iframe and render it. If you don't prefer Iframe then you can embed simply a BodyElement from the dart:html library directly.
An example of embedding Iframe is availabel here. Eventhough its from an old repo, the code is valid and I couldn't find a latest one.
If you don't want do go the tough way, there is simplified widget from Rodydavis which is available here called easy_web_view.
Still if you need code sample a create simple dart pad and share the MRE, I will try to help. :)
For the Iframe example, you can do something like this
First, import 'ui' library, and 'html' library.
import 'dart:ui' as ui;
import 'dart:html';
Second, register your 'Iframe' with viewType 'test-view-type' just for example.
ui.platformViewRegistry.registerViewFactory(
'test-view-type',
(int viewId) => IFrameElement()
..width = '640'
..height = '360'
..src = "https://www.youtube.com/embed/5VbAwhBBHsg"
..style.border = 'none');
Note: you will notice that the compiler can't find platformViewRegistry method but it's okay if you choose to Debug anyway and it will run correctly without any problems.
Finally, use HtmlElementView widget to run this Iframe
return Scaffold(
body: Column(
children: [
Text('Testing Iframe with Flutter'),
HtmlElementView(viewType: 'test-view-type'),
],
));
You can use this package flutter_widget_from_html
While defining the widget you need to set webView: true to get iFrame support
I just tested and it is working fine on web, and this package supports local assets too

I want to create an angular app to show live code preview like Jsbin

I'm creating the Angular app which lets user save his html code (maybe it has style and script tag to control the view) and there is a live preview next to it. User can save the code and other users can come to see the code and the preview. I also worry about the security because of script tag and I want the script to work only with the code that user provides (Not allow to control or get the data in the parent frame). So I need some suggesting of how to do it.
I have tried the preview with iFrame by giving the value through the 'srcdoc' property, but it looks like the security is bad.
You would not need to use an iframe in that situation, you can just render an HTML string inside of a div element using the innerHtml input like so:
<div [innerHTML]="htmlString"></div>
Where htmlString is a string containing the HTML code. You will have to sanitize the content of that variable with the DomSanitizer.
constructor(private domSanitizer: DomSanitizer){}
...
ngOnInit() {
this.htmlString = this.domSanitizer.bypassSecurityTrustHtml(yourHTMLString);
}

Coded UI: Find Element(s) by CSS Selector

I am trying to build out a harness for a page so that we can write tests against it. What I would like to be able to do is use a CSS selector to find the given element or elements instead of manually modifying the SearchProperties or FilterProperties.For a web test the CSS Selector seems far more intuitive then the SearchProperties do. Is there some mechanism for doing this that I am simply not seeing?
Try this...
https://github.com/rpearsondev/CodedUI.jQueryExtensions/
It adds extension methods to the BrowserWindow object...
var example1 = browser.JQuerySelect<HtmlHyperlink>('a.class1');
var example2 = browser.JQuerySelect<HtmlListItem>('li.class2');
However, I will let you know I'm having issues with it complaining about casting errors regularly.
Try browserWindow.executeJavascript if you return a control you found via css/xpath it returns the relevant uiControl object
const string javascript = "document.querySelector('{0}');";
var bw = BrowserWindow.Launch(new Uri("http://rawstack.azurewebsites.net"));
string selector = "[ng-model='filterOptions.filterText']";
var control = bw.ExecuteScript(string.Format(javascript,selector));
HtmlEdit filter= control as HtmlEdit;
filter.Text = "Alien";
As sjdirect noted, the jQuery extensions are probably the way to go if you want to use those type of selectors.
However, it seems that you may be interested in some abstraction that doesn't require directly setting search / filter properties on the UITestControl objects.
There are good abstractions that do not use the same selectors as jQuery, but provide a readable, consistent approach for finding elements in the page and interacting with them.
I would recommend also looking into Code First and CodedUI Fluent (I wrote the fluent extensions) or even CodedUI Enhanced (CUITe).
These provide query support for that looks like (from CUITe):
// Launch the web browser and navigate to the homepage
BrowserWindowUnderTest browserWindow = BrowserWindowUnderTest.Launch("https://website.com");
// Enter the first name
browserWindow.Find<HtmlEdit>(By.Id("FirstName")).Text = "John";
// Enter the last name
browserWindow.Find<HtmlPassword>(By.Id("LastName")).Text ="Doe";
// Click the Save button
browserWindow.Find<HtmlInputButton>(By.Id("Save")).Click();

I am trying to retrieve a webpage html with webclient and display it with webbrowser in C#

I have the following code snippet:
WebClient client = new WebClient();
String htmlCode = client.DownloadString(newurl);
webBrowser1.DocumentText = htmlCode;
BTW, webBrowser1 is defined globally elsewhere in the program. Likewise, "newurl" is a valid url also defined globally elsewhere.
WebClient gets the complete html which I pass to webbrowser1 using DocumentText.
This result is all kinds of link, syntax, remote javascript, and other errors as though the html is corrupted. However, if I use
webbrowser1.Navigate(newurl);
the target page displays just fine.
I am getting the source html so I can make changes before I display it.
Clearly I am missing something.
Any thoughts?
Regards,
Jim
webBrowser1.DocumentText = htmlCode; will set the HTML only, but will not load any linked-in resources, such as JS, images, CSS, ... .
If you want to do, what you seem to want to do, you can e.g. load the HTML via a WebClient, rewrite it (this includes changing relative paths to absolute ones or setting a base url), write it to a file, then webbrowser1.Navigate("file://path/to/file");

Is it possible to create custom XUL elements from XPCOM or NPAPI?

I was wondering if it is possible to create a new XUL component via any available api, such as XPCOM or NPAPI, so we can use it our XUL files.
Let's say I wanted to clone the XULs vbox's components code and add a few modifications to it, so we could use our custom XUL component just like this:
<window>
<myvbox mycustomarg1="customValue"> Some content... </myvbox>
</window>
I know what XBL is and what is used for and it doesn't fit our need.
Any suggestion of how to achieve that?
Edit:
We need to create a browser component in Firefox as child of another browser object. The problem is some websites detect this child browser as iframe and we want to avoid this.
Thanks.
If the point is preventing a webpage loaded into a frame from messing with your XUL document then you should use <browser type="content"> - this establishes a security boundary between chrome and content which (among other things) prevents the content document from accessing its parent frame. It is important however that your XUL document itself is loaded as chrome and not content (by either being on top level or inside <browser type="chrome">). See https://developer.mozilla.org/en/XUL/Attribute/browser.type for documentation.

Resources