This project demonstrate Chrome/Edge browser extension native messaging to native apps on Windows OS
Mainly contains these sections
- YoutubeAssist visual studio project (YouTubeAssist.sln)
- YoutubeAssist WPF app, this is the native app
- ClientHost console app, this is the standard IO app that browser extension can connect to, then this app will use IPC(NamedPipe) to connect to the native app, like a broker between the native app and browser extension
- Web app and browser extension (in the Web directory)
- WebApp, a web server for demo purpose
- WebExt, the browser extension
sequenceDiagram
autonumber
participant External as WebApp/WebExt script
participant WebExt_SW as WebExt ServiceWorker
participant WebExt_Host as WebExt Host(StdIO)
participant Native
alt WebExt Popup open or click connect button
WebExt_SW ->> WebExt_Host: Invoke native Host
Note over WebExt_SW,WebExt_Host: Port created
WebExt_Host ->> Native: Establish IPC
Note over WebExt_Host, Native: NamedPipeStream created
end
alt Message flow
External ->> WebExt_SW: Send JSON message
WebExt_SW ->> WebExt_Host: Post JSON message<br>to native host
Note over WebExt_Host: Read message from StdIO
WebExt_Host ->> Native: Write message string to pipe
Note over Native: Read message from pipe<br>And handle message
Native ->> WebExt_Host: Write response string to pipe
Note over WebExt_Host: Read message from pipe<br>And write message to StdIO
WebExt_Host ->> WebExt_SW: Send response to SeriveWorker
WebExt_SW ->> External: Send JSON response
end
Open the YouTubeAssist.sln
in visual studio and build the solution
This project need windows 11 SDK(10.0.26100.0), which can be installed from visual studio installer -> Individual components
This app will use a post-build.bat
file to write registry key according to this browser extension nativeMessaging documentation
- Install Nodejs 20.10.0+
- Install yarn 4.5 according to installation doc
- Go to the
Web
directory, run these commandyarn install
yarn build-ext
#build brower extensionyarn build-app
#build web app
The browser extension and web app will be in the build
folder, then load the extension from chrome://extensions/ developer mode
- Build the ClientHost app, YoutubeAssist WPF, WebExtension, WebApp
- load WebExtension in Chrome/Edge, and run
yarn start-server
under theWeb
directory - Launch the YoutubeAssist WPF
- Open browser extension popup, a port would be created by using
chrome.runtime.connectNative
and connect to the WPF.- In windows task manager, a
ClientHost
process will also be created
- In windows task manager, a
- Send messages between WPF and browser extension
- Click the
Authenticate by Windows Hello
button on popup, windows hello challenge will prompt - Open a new tab and go to
http://localhost:3000
, click the Click theAuthenticate by Windows Hello
button on the web page, windows hello challenge will prompt