How to allow blocked content in an embedded Webbrowser in c#? - c#

I'm developing a c# application that embeds the Webbrowser control. I create the Website dynamically and use NavigateToString() to display it. I'm on Windows 8 with IE10.
Now my Problem is: Javascript won't execute. For example I added a link that calls alert and another one that calls reset() on a form. Both do nothing. I believe it has to be some security issue because when I say the generated page and open the file manually in IE10 and click one of those links, I get a popup at the bottom that says "Internet Explorer restricted this Webpage from running scripts or ActiveX controls." and a "Allow blocked Content"-button. If I just Close the popup, nothing happens, if I click "Allow blocked Content" the JavaScript works fine.
How can I enable JavaScript in the embedded Webbrowser?

How are you accessing this local website? is it localhost? you need to make the url security friendly so it doesn't get blocked, give it a url http:// localhost:someport instead and it should work

Related

Is there any way to fully control browser from application?

I was trying to make a pc application that helps people more conveniently when they are using a browser(e.g Chrome, Firefox, Edge ...)
For example, the application shows the default browser and let user can choose another browser as default if they want to, and the app shows all windows that are currently opened; Overmore, when the user clicks a specific window then app will focus the window.
user can select default browser
user can see all windows categorized by browser type
So, my initial planning was using Election js; however, I've found that there is no way to control a browser from the Electron application since Node js cannot access the users' system(this thinking could be wrong since I have poor English😥)
After some research, I'm guessing C# can do that by using windows api. I've saw this post that saying by using DDE, we can get tabs urls.
But I'm wondering if C# can fully control a browser; for instance, create a new window, notice if music or video is playing in the tab, request to browser for getting favorites list.
If it cannot, how about requesting api to the browser from pc application?
You cannot fully control a browser. Internet Explorer was the only browser that had a documented and supported API to control, inspect and automate. Internet Explorer is dead so this is a dead end. The basic DDE control interface is also outdated.
Accessing favorites and the content of open tabs is limited because evil people would use such APIs to inject and spy. If you want to access the favorites you will have to write custom code for each browser.
Using the accessibility and UI automation APIs is the only reliable and supported way of interacting with modern browsers. SetWinEventHook can be used to detect window creation and primitive state changes. MSAA/UI Automation needs to be used to get more information from each browser window.
The thumbnail API and/or magnifier API can be used to get the preview image.
To open a new tab, execute a new process with the URL on the command line. Some per-browser customization might be required (-new-tab parameter etc).
Use IApplicationAssociationRegistration::QueryCurrentDefault to detect the default browser.

Webbrowser control issue with cookies

i have created web browser control in c#. I used to open .net website into this control. Once page is completely loaded.i was using cookies of this browser control to create httprequest and used to execute request. I used to get data which was needed for me.
But all of sudden this stopped working. I checkd to see what happened then i found that issues are with cookies are being formed throught browser control.For example, if i use page url on IE browser and then get cookie and supply it to httprequest. It works good. But same thing with web browser control is not working now.
Another thing, Forget about httprequest, Download from webbrowser control itselft is also failing. But its working in IE. What could be stopping it to download fail in web browser control and work in IE.
Dont understand how.please help.
This issue is not with the cookies. it is with the browser emulation. By default webbrowser control take IE emulation. but if you need to mention which browser version you want control to use. By using registry.
I emulated IE to my application by changing registry information. and it started working.

Schema URIs in Windows Store Apps vs Chrome

I'm developing an app for Windows 8.1 called myTrip and I'm implementing my custom scheme URI for the app. I want this URI : mytrip:place:/m/0942y1 to open my app and navigate to a place with that ID. I have the logic done, it works fine if I run it from Windows + r. I want to distribute this uris in a facebook page, and when a user clicks on it, the app will open and the place shown. It's more or less the same thing that the windows store web page of your app does:
http://apps.microsoft.com/windows/en-us/app/mytrip/ae689d16-f349-4596-8bc7-e0eeab87ec24
This works in IE and Chrome, the schema that opens the store app is this:
ms-windows-store:PDP?PFN=19185FernandoUrkijoCerced.MyTrip_q1p7rzex4ekjr
If you copy and paste it on Chrome, and you have Windows 8, the app store will open. But, if I try with my custom URI:
myTrip:place:/m/0942y1
It only works on IE, not on Chrome. Why the Windows app store schema URI works with Chrome and not with my schema? Any ideas or hacks to bypass this problem?
Thanks you.
Chrome does not automatically recognize custom protocol handlers. Firefox will recognize when you are trying to use a protocol handler and offer to create a protocol handler definition for you. IE recognizes them.
On top of this, Chrome by default excludes protocol handlers it doesn't know.
In order to add your app's handler to Chrome:
With Chrome Closed
Navigate to "C:\Users\%Username%\AppData\Local\Google\Chrome\User Data"
Edit the file "Local State" with Notepad (or Notepad++)
Go down to the section marked "protocol_handler". You can also search for "ms-windows-store"
Add a line in "excluded schemes": "myTrip": false,
Save the file
Start Chrome
You should be able to use your protocol inside Chrome now.

Open IE and read page for IE 7 or newer c#

I need to open a browser (Internet Explorer 7 or above) for a given URL and then read the contents once it has finished loading. leaving the browser open for the user to use as normal afterwards.
Then I need to replace the page (if still open) with a new URL later if needed and read that page...
As I'm needing to leave them in IE after I have read the page I assume I can't use the browser control, so how would I do this?
This is a windows classic forms app using .Net4.
many thanks.
It can be done. Look http://www.codeproject.com/KB/shell/AutomateShellWindow.aspx
Once you have access to IWebBrowser2 you can do everything you need, including navigate, read content etc.

can webserver recognize webbrowser control vs internet explorer software when user load page?

can webserver recognize webbrowser control vs internet explorer software when user load page ?
if i load page through webbrowser control in c# i get "500 server error"
when i do it in the internet explorer software it work o.k.
why there is diffrent behevior and how i can manage that ?
thanking in advance.
That sounds like maybe it is reacting to a different cookie
value or similar. WebBrowser is IE (to most purposes). A 500 is at the server, but WebBrowser is the client.
You might be able to hook WebBrowser to supply a different user-agent, but by default it should appear the same.

Categories

Resources