C# plugin for Google Chrome - c#

Can I communicate to Google Chrome in C#?
For writing a chrome plugin for example.

<Spoilers>
Quick short answer: No, because Extensions require JSON, JavaScript, and HTML.
</Spoilers>
Hi Tony,
There are multiple templates on the internet that you can download to build a chrome extension project using Visual Studio.
Downloading one of these templates just gives you the files and folders that you need which I call "the setup".
That won't let you build a Google extension using C#.
Andrey mentioned that there are libraries like Bridge.NET that will compile your code into HTML/JavaScript. That will help you write HTML and JavaScript using C#. You still need a manifest.json file.
I don't recommend that. That library is not designed for Chrome Extensions. Also, you will have to compile the code into JavaScript and store that JavaScript code in a JavaScript file. I recommend using HTML/JavaScript with no compilers when building your Chrome Extension.
You need to keep in mind that there are 3 main parts in a chrome extension. These are:
manifest.json
A JavaScript file
HTML file
There are multiple steps and it's not hard to build a google chrome extension. This link will give you the complete tutorial on developing a chrome extension with detailed explanation. This tutorial installs a template so that you can develop it in Visual Studio just like I mentioned before.

What I have done to address is use Simple Message Host, it will trigger an executable on the local machine that you code in c#, sending stdin messages and listening to stdout messages so you can build this host to use as a bridge, but like I said, it needs to be on your local network at least, and you have to do some editing in the windows registry, so it has its limitations.
But for the system I am working with, this solution worked perfectly because I have a controlled environment that I can set up all these prerequisites.
So, just to clarify, what I did here is:
Create a chrome extension with background.js opening up the listener to the website's javascript.
Add a registry in windows registry pointing to the path of the executable.
Create the executable in C# doing all your logic.
Send a response from the executable to the extension and then back to the website.
There are several guides on how to do this, so I won't detail these steps here so I don't replicate it.
But for the moment, it is the best way to do what you want, if you have control of your environment that is.
So, if your plugin (extension or chrome app) will work on a controlled environment, this is the way to go, otherwise, I would consider something related to ClickOnce perhaps or WebAssembly but that's not fully released yet.

Chrome own extension manager supports extensions written in js and html.
that said, to execute c# code within the extension you have two options:
Compile c# code to javascript code which then can be added as a normal javascript extension to chrome (take a look at scriptsharp)
Use c# as a back-end system. just like most of download managers:
for case 2 you need a c# application installed in client device(or in the cloud) listing to a specific port (using httplistener or self hosted webapi (you can use netcore) which do these steps
Listing to incoming requests
parse request data eg. json and do something with it
return the result to javascript extension which can display it to user or do other things with it.

The topic is quite old, but I'd like to share that sample:
https://github.com/Retyped/Demos/tree/master/ChromeDemo
In a few words, the sample is implemented in C#. The Retyped.chrome NuGet package provides bindings (Chrome API) for Bridge.NET projects. So yes, now you can implement your logic in C#, then C# code will be transparently compiled into JavaScript by Bridge.NET compiler.
With that approach you can build your Chrome extension on top of .NET Framework as well as utilize thousands of JavaScript libraries.

Related

Targeting a specific Chrome process?

When I open the Chrome's Task Manager, I can see something like this?
Now, programatically, is it somehow possible to target the Chrome instance that is being used to run the Flash Plug-In? Maybe using System.Diagnostics.Process class or native API calls?
I was able to do this with native api calls. My solution worked perfectly on my machine. Here is what I did:
First, get Microsoft Process Explorer. Using this tool, I was able to get the flash plugin dll's name that chrome uses which is called pepflashplayer.dll in my case.
Next, a little search on Bing got me this article. It's C code so I converted to C# and after some coding I was able to retrieve the correct Chrome process ID that uses flash plug-in.
I have uploaded my solution to SkyDrive for you to check here. Note that I am not closing any handles in my sample so you'll have to add that for a real project.
There might be better solutions out there but this one should work. Hope it helps.

Editing Documents (.doc) in Browsers

I've been developing a web application with asp.net webforms and in this app I have some documents (.doc, .docx, .rtf files), and my client want to edit these files on browser, they want to open a document in an editor, edit, save it on server (without downloading) and close it. I know it's difficult but I would like to know if it's possible or if is there any easy way to do it. We find something like SkyDrive of Microsoft.
PS: We can pay for components if you can suggest something that really works.
Thank you!
IF the clients have Office installed:
I would recommend http://www.webdavsystem.com/server - this allows you to build a "virtual filesystem" (WebDAV which is based on HTTP) which Office can access thus allowing the client to open/edit/save a document (DOCX etc.) via HTTP(S)... it is pure .NET, integrates nicely with ASP.NET and has even a JavaScript accessible API... esp. the upcoming V 3 comes with a wizard which allows you easily to add that funcionality to your ASP.NET application... (just a happy customer, not affilliated).
IF the clients don't have Office installed then it gets tricky:
To really fully support you would need some sort of Silverlight/Flash/ActiveX/JavaApplet which runs in the clients browser and supports the needed editing features...
I am not aware of such production-quality components except the ones from Microsoft - see http://www.microsoft.com/en-us/office365/online-software.aspx
You could integrate them into your web application although they won't offer the full Office feature set in the browser...

Building a Silverlight application upload utility?

This post is really more of a discussion if this is even possible.
There are numerous examples all over the web, but all of those are using asp.net applications and unfortunately I can't go that route. So my goal is to build an upload utility in Silverlight that can be deployed as a CRM 2011 web resource, without using anything Asp.Net related.
I have looked at the Telerik SL upload control, but it appears to require a ServiceURL handler and I'm not sure I can embed something like that within Silverlight and make it work?
I guess I'm looking for some direction here on what my options would be. I don't want to start down one path and run into a brick wall.
Thanks for reading!
Your SL control can upload the bytes of the file as an attachment (in the Notes area) to the entity record. Here is a project on CodePlex that uses SL to upload an image as an attachment:
http://crmattachmentimage.codeplex.com/
Hopefully that will get you pointed in the right direction!
I haven't really looked into the creation of web-resources from silverlight, but considering the web-resource utility would be using the CRM SOAP end-point, I imagine you could do the same from Silverlight.
From Silverlight, you would either need to make a reference to SOAP End-Point url which can be found in the CRM client in Settings -> Customization -> Developer Resources.
Otherwise, you could use the open-source project CrmSilverSoap library which already has all the generated proxy classes as well as a few helper methods for connecting to the various CRM services.
In trying to work with and create the web resources, I'd have a look at the this SDK article which shows to how to use some messages for Creating Web Resources. You will need to make the required modifications to code to enable these messages to be sent via the reference soap end-point in silverlight.

Emulating PHP page to get response in C#

I browsed internet but haven't found my answer... as I'm running out of ideas, I'd appreciate some help on this issue.
So here it is:
I have some PHP code that takes a path to a file and returns a bunch of information that i need.
I have the source code (it is open source), and i know my C#.
My problem is i want to be able to use this PHP code from a C# application, offline, emulating the PHP code.
Any ideas?
Thanks.
If you really must, you can always launch the PHP interpreter from C# by spawning a process. I'll leave the details to MSDN. Better, though, would be to just translate the PHP to C# by hand.
You could set up a PHP server on the local machine and invoke the file using an HTTP request created with c# (such as with the WebRequest object). This satisfies the requirement of working offline and since you have the PHP code, you can make minor modifications to accommodate whatever parameters you need to pass into it.
However unless this is for an isolated case in a controlled environment, I would not suggest it.
If this is for distribution to user machines it would be a) impractical to deploy and b) a maintenance nightmare. If you are running on a server and rewriting the PHP in c# is not an option, it should get the job done.
It sounds like to either wish to
Translate the PHP code to C#
Call the PHP code from .NET
???
I don't think emulation is the term you're looking for, exactly.
If you can link to the PHP code (if it's OSS, is there a site with more information?) or paste it here, we can probably let you know the best way to handle this.
If you don't want to translate the PHP code into C# then you must invoke the PHP interpreter.
First, look at the license on the PHP code you would be using. When I looked at the code earlier I noticed that all but one PHP file had a GNU GPL license on it. GNU GPL should work for what you want, but I recommend that you review the GNU GPL if you haven't done so already. You should also look into what license is supposed to be applied to the last file before continuing.
Second, rewrite the entry file. The file in question is upload_file.php. This file loads the other files as includes, parses the SC2 replay file, and generates an output for use by a web browser. You just need to rewrite this file to have it output a simplified version of its output to the console. You might have it receive the name of the replay file from command line arguments. The other files that are marked as GNU GPL can just be copied directly into your project. I should also say here that there may already be a console version. Take a minute to look around for one.
Third, write a C# application. Invoke the PHP interpreter telling it the what file to interpret, and the name of the replay file to parse. You will need to redirect the console output from your PHP instance into your C# code to be able to read the output.
Fourth, read the output.
Fifth, parse the output for use in your C# application.
Old thread but figured it could use an answer.
You could use the codeplex Phalanger. http://phalanger.codeplex.com/ It allows you to take existing php files and compile them to .net

How to write FireFox extension with Visual Studio using C# programming language?

I was wondering if it's possible to write Firefox extension using .Net Framework?
Had anybody such experience in writing Firefox extensions using C# programming language?
Any good sites or guidelines would be very helpful.
FFPlugin http://img81.imageshack.us/img81/3049/ffplugin.jpg
Here is an example of what I need. Extension to enter phone number and to send SMS Message.
I draw it in Paint, so I'm sorry for having no artistic touch.
Assuming you're asking about writing an extension (and not a plugin), the best place to get started is with the info at the Mozilla Dev Center.
Konamiman is correct: extensions are mostly XUL (an XML grammar) and Javascript, packaged into a ZIP file with the extension .xpi. The various links from the page I linked should answer basic questions, like the one you posted above:
https://developer.mozilla.org/en/Building_an_Extension
https://developer.mozilla.org/en/Extension_Frequently_Asked_Questions
Firefox extensions are written primarily in Javascript. See here: http://www.rietta.com/firefox/Tutorial/backend.html. So unless you can find a way to convert C# code/.NET Framework objects to Javascript, you are out of luck.
As has been observed by other respondents, Firefox extensions are primarily written in Javascript: but you're in luck, because Script# is a free tool that enables developers to author C# source code and subsequently 'compile' it into Javascript.
I'm not sure how you'd do for C#, but you can use XPCOM to call native code libraries: that's how the Glasser extension, for instance, is able to use the Windows-specific Aero effects.
IBM hosts a very good XPCOM tutorial at DeveloperWorks.

Categories