Calling ActionScript (Flash) method via mshtml from C# - c#

I use the WebBrowser component from WPF. I load there a page from Internet and I access the Document property to call my scripts. Unfortunately calling scripts don't work as I need. When I am calling JavaScript methods which exist in JavaScript so it works great but when I need access some methods which are available through Flash so I have problems.
document.parentWindow.execScript("document.getElementById('swfObject').methodFromActionScript();", "JavaScript");
I get an exception in the browser Object doesn't support this property or method. In C# I get Exception from HRESULT: 0x80020101
But when I try launch this code in a regular browser as IE or Chrome by passing it into URL so the code is executed and I see results.
Maybe some trustmode issues or what else could deny access to Flash properties and methods?
BTW: The var allowScriptAccess is set to always.
Thank you for help.

Ok, I've found an issue. Before this execScript. I was doing some modification of DOM and moving elements and apparently this has broken DOM so I couldn't call swfObject because during moving it was somehow modified and lost its properties and methods which were exported via ActionScript.

Related

C# Get element in chrome browser WITHOUT Selenium. Just pure C# code

Is there a easy way to get a element from chrome without using Selenium? Just pure C# code
I was thinking to somehow get the current tab HTML source code and get all the element values that way. Does anybody have any idea how to do this? And it needs to be a already active browser. So i can't use any HTTP request
You're looking for a C# interface to the Chrome DevTools Protocol. There is such a thing, unsurprisingly called ChromeDevTools. The included sample shows you some DOM navigation code.

How to add a stylesheet into a WinForm WebBrowser in C#?

I am wanting to manipulate a page being loaded in a WebBrowser by adding a stylesheet on the DocumentComplete event. I'd like to do it without using an external file, if possible.
Most of the solutions I've seen involve deprecated methods or libraries such as mshtml. The MSDN says that the accepted method is to use HtmlElement myelement = mywebbrowser.Document.CreateElement(
"style"), but nothing else. Manipulation of such seems to be problematic - things like trying to set InnerHtml throws an error at runtime (ie, System.NotSupportedException: Property is not supported on this type of HtmlElement).
Given all that, what is the best/proper way to add a big chunk of CSS to a page loaded in a WebBrowser?

How do I reference a local instance of Jquery in a Webview

I have a C# Windows Store App with a WebView which loads some local HTML. I do this via the NavigateToString method. I want to include jQuery but so far the only way I can get this to work is either using the ajax hosted libraries or pasting the entire library into a script tag on the same page.
I've tried putting it in the Assets folder, ensuring that its set to Content / Copy If Newer, and I've tried the following paths to it with no success
Assets/jquery-2.1.0.min.js
/Assets/jquery-2.1.0.min.js
./Assets/jquery-2.1.0.min.js
~/Assets/jquery-2.1.0.min.js
ms-appx:///Assets/jquery-2.1.0.min.js
I've tried putting it in a /js subfolder in the app, as I've seen this done in some examples online. I've also tried adding JQuery through NuGet. Neither of these steps really made sense to me and they obviously didn't work, but I thought they were worth a try.
As usual, I got the inspiration to try one more thing while finishing up my StackOverflow question. This works:
ms-appx-web:///Assets/jquery-2.1.0.min.js
This URI Scheme ms-appx-web is mentioned in this msdn post, but it doesn't explicitly state in which cases it should be used over ms-appx:. I guess accessing local resources from a WebView is one of those cases.

How to access text inside flash object

I've got to access text inside a flash object. The preferred method is via C#, but anything that works will do. The only requirement is that I'll need the resulting information to be transferred back to c# code.
Let's take, for example, this page.
With fireflashbug, you can easily access individual elements inside flash object and read/change html texts inside each of them.
To work, it requires Flash Debugger.
How can I do the same from my own code?
You can use AS3 ExternalInterface with or without JS. Check this thread too:
C# and Flash communication
To communicate with a flash object you use Javascript.
Here are some tutorial and examples:
http://www.adobe.com/devnet/flash/articles/external_interface.html
http://csl.sublevel3.org/howto/javascript_flash_callbacks/
http://www.permadi.com/tutorial/flashjscommand/
Now, once you have your data using javascript you can pass them to an input element and pass it to code behind if you wish for.
and many more on google

Internet explorer add on and the website

Is the website able to determine if a particular IE add on has been installed or not?
How do you have the web page detect the IE add on?
In general, no; however it depends on what the add-on does. If it modifies the web page in some way (e.g. removing ads) then it should be possible to use Javascript to detect if the current page has been modified.
If the addon is available via Javascript/ActiveX interface, its absense may be checked by catching an exception on calling some (missing) addon's function.
This way, checking for few common addons leads to nice browser's fingerprinting method.
Refer to: http://www.informatica64.com/Wbfingerprinting/
No doubt you can detect most through JavaScript; it'd be addon-specific.
In IE just expose an Active X control from your add-on, and then instantiate it using new ActiveXControl() inside a Javascript try {} block. If it succeeds, your extension is installed. If it fails, probably not. You can even expose a .version() method to get the version of the control.

Categories