question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Google Chrome Extension compatibility in Node-webkit: How to make desktop/screen share work?

See original GitHub issue

My Situation:

I am working for a large hospital project where i need to use Node-Webkit (and stop depending on Opera, Google Chrome, Chromium 46). My biggest issue is right now desktop share (Which worked perfectly fine with Google Chrome and Chromium 46). But i need to make it compatible with node-webkit.

Problem in node-webkit:

If you open this URL in node-webkit https://talky.io/nodenode then you can do WebRTC video/audio test calls fine.

But, then when you press desktop share button it does not work because the extension is in Google chrome webstore (try with Google chrome stable it works)

FYI: this is how we make extensions for Google chrome for that desktop share.

manifest.json:

{
  "name": "Screen sharing",
  "author": "iMeMySelf",
  "description": "Screensharing BLABLA",
  "homepage_url": "https://www.domain1.com/",
  "version": "0.0.2",
  "manifest_version": 2,
  "minimum_chrome_version": "34",
  "icons": {
    "48" : "icon.png"
  },
  "permissions": [
    "desktopCapture"
  ],
  "background": {
    "scripts": ["background.js"]
  },
  "content_scripts": [ {
    "js": [ "content.js" ],
    "all_frames": true,
    "run_at": "document_start",
    "matches": ["*://*.domain1.com/*", "*://*.domain2.com/*"]
  }],
  "web_accessible_resources": [
        "icon.png"
  ]
}

background.js:

/* background page, responsible for actually choosing media */
chrome.runtime.onConnect.addListener(function (channel) {
  channel.onMessage.addListener(function (message) {
    switch(message.type) {
      case 'getScreen':
          //channel.sender.tab.url  = 'https://nodewebkit.domain1.com';// this works for version 40
          var pending = chrome.desktopCapture.chooseDesktopMedia(message.options || ['screen', 'window'], 
                                                                 channel.sender.tab, function (streamid) {
              // communicate this string to the app so it can call getUserMedia with it
              message.type = 'gotScreen';
              message.sourceId = streamid;
              channel.postMessage(message);
          });
          // let the app know that it can cancel the timeout
          message.type = 'getScreenPending';
          message.request = pending;
          channel.postMessage(message);
          break;
      case 'cancelGetScreen':
          chrome.desktopCapture.cancelChooseDesktopMedia(message.request);
          message.type = 'canceledGetScreen';
          channel.postMessage(message);
          break;
    }
  });
});

content.js:

/* the chrome content script which can listen to the page dom events */
var channel = chrome.runtime.connect();
channel.onMessage.addListener(function (message) {
    console.log('channel message', message);
    window.postMessage(message, '*');
});

window.addEventListener('message', function (event) {
    if (event.source != window)
        return;
    if (!event.data && (event.data.type == 'getScreen' || event.data.type == 'cancelGetScreen'))
        return;
    channel.postMessage(event.data);
});

How can we make that extensions compatible for Node webkit please?

<bountysource-plugin>

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource. </bountysource-plugin>

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
sean220commented, Feb 2, 2016
//nw12 
//var gui = window.require('nw.gui');
//if(gui.Screen.Init) {
//            gui.Screen.Init();
//}
//gui.Screen.chooseDesktopMedia...

//nw13
nw.Screen.Init();
nw.Screen.chooseDesktopMedia(["window","screen"],function(streamId){
                if(streamId) {
                    var vidConstraint = {
                        mandatory: {
                            chromeMediaSource: 'desktop',
                            chromeMediaSourceId: streamId,
                            maxWidth: 1920,
                            maxHeight: 1080
                        },
                        optional: []
                    };
                    attachToWebRTC({audio: false, video: vidConstraint});
                }
            })

//add to the webrtc peerConnection
function attachToWebRTC(conf){
        navigator.webkitGetUserMedia(conf,function(stream){
            //peerConnection.addStream(stream);
        },function(e){
            console.error(e);
        })
    }
0reactions
rogerwangcommented, Sep 30, 2017

Please ask questions in our mailing list: https://groups.google.com/forum/#!forum/nwjs-general

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using the Screen Capture API - MDN Web Docs
In this article, we will examine how to use the Screen Capture API and its getDisplayMedia() method to capture part or all of...
Read more >
A Quick Guide To Chrome Compatibility Mode | LambdaTest
Google Chrome has a feature where you can enable Chrome compatibility mode to experience the older versions of your current browser with ...
Read more >
Is it possible to load chrome extension in node-webkit window
Loading Chrome extensions is supported now with '--load-extension' switch from Chromium. Previously, since node-webkit was based on Content Layer of ...
Read more >
WebRTC Screen Sharing
Share screen from chrome and view over all WebRTC compatible browsers/plugins. You can open private rooms and it will be really "totally" private!...
Read more >
Screen capture in Google Chrome - Twilio
To build screen sharing capabilities into a WebRTC video chat application you must first be able to capture the content on screen.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found