Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing chrome extension in C#?

Today I started looking at the Chrome extensions the first time ever, I have a very silly questions, I am sure the answer is NO to this as per google search but I just wanted to make sure from the community here.

  1. Is it possible to use C# to write code instead of javascript?
  2. Is it possible to use Partial Views (ASP.NET MVC) in chrome extension as it renders HTML?
  3. I found this in VS Marketplace https://marketplace.visualstudio.com/items?itemName=MadsKristensen.GoogleChromeExtensionProjectTemplate Is there any other templates which have bootstrap etc

Cheers

like image 853
Ali Avatar asked Sep 29 '17 06:09

Ali


2 Answers

You can create browser extension with C#. Specifically, Using Client-side Blazor.

To publish, the following operations are required.

First, you publish like normal standalone app. https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/blazor/webassembly?view=aspnetcore-3.1#standalone-deployment

Then, Remove the underscore from directory name. Since it cannot be used in the extension.

# remove underbar from directory name
mv _framework/_bin _framework/bin
mv _framework framework
# rewrite
sed 's/_bin/bin/g' framework/blazor.webassembly.js
sed 's/_framework/framework/g' framework/blazor.webassembly.js index.html

Then, Add manifest.json and setting CSP like this,

"content_security_policy": "script-src 'self' 'unsafe-eval' 'sha256-v8v3RKRPmN4odZ1CWM5gw80QKPCCWMcpNeOmimNL2AA='; object-src 'self'",

Blazor boot script add script tag to html, so you should add scripts hash to allow execute bootup script.

This is sample app I created. https://github.com/key-moon/WeatherForecastExtensionWithBlazor And, This is commentary (wrote in Japanese). https://qiita.com/keymoon/items/03357e58eddf75871527

like image 113
keymoon Avatar answered Nov 05 '22 04:11

keymoon


Chrome Extension runs in the browser so you can not use C# in Chrome Extension Development.

Again the Chrome extension runs in the browser so you can not use ASP.NET MVC in Chrome Extension Development, but you can use ASP.NET MVC or any other language at server to generate the views and render them in the chrome extension using ajax.

Have a look at this: https://github.com/Ehesp/Chrome-Extension-Twitter-Bootstrap-3-Template

like image 36
elegant-user Avatar answered Nov 05 '22 04:11

elegant-user