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.

restrictions on chrome.tabCapture.captureOffscreenTab()

See original GitHub issue

NWJS Version : 0.35.2 Operating System : Win64 (but supposedly applies to all systems)

Expected behavior

    function onTabStream(stream) {
        console.log(stream, chrome.runtime.lastError);
    }
    chrome.tabCapture.captureOffscreenTab('render.html', { audio: true, video: true }, onTabStream );

Should result in stream being a MediaStream object, regardless of whether the start_url (first argument of captureOffscreenTab) is an http(s)/data protocol URL or a relative URL in the nwjs app’s scope (or using a chrome-extension protocol URL).

Actual behavior

stream is undefined and checking the message in chrome.runtime.lastError, it states "Invalid/Missing/Malformatted starting URL for off-screen tab." This is due to restrictions in Chromium’s /chrome/browser/extensions/api/tab_capture/tab_capture_api.cc, which should not be applied to nwjs context.

How to reproduce

Try to capture a page (“render.html” in these code examples) in the nwjs app’s context as a hidden tab - see code above.

Temporary workaround(s)

  1. I managed to circumvent this issue by serving the file(s) I need in the hidden tab as http via the connect and serve-static packages (let’s say on port 3000) and then loading 'http://localhost:3000/render.html'. But of course this leads to not being able to use node/nwjs API calls directly in the page’s scripts, no direct communication between the tab and the rest of the app (or having to workaround that by using ajax to access an intermediary file) and other restrictions (mixed-content problems would have to be handled by serving as https and potentially handling certificate problems… etc,).

  2. Another makeshift solutionis to open the page to render in a separate window and hiding this with a mixture of options and a minimize() call:

  nw.Window.open('render.html', {
      show_in_taskbar: false,
      resizable: false,
      focus: false,
      frame: false,
      width: 0,
      height: 0
  }, function(w) {
      win.width = 1920;
      win.height = 1080;
      w.minimize();
  });

This results in the popup flickering shortly when starting up the application, but interaction between the page and the rest of the app is possible without restrictions. However, there are small black bars on top and bottom of the rendered output that I can’t get rid of so far, and (I fixed the black bars by setting the width and hight specificly before minimizing the window in the callback.) I think the performance is a bit worse than the captureOffscreenTab() solution.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
rogerwangcommented, Dec 20, 2018

This is fixed in git and will be available in the next nightly build.

Read more comments on GitHub >

github_iconTop Results From Across the Web

chrome.tabCapture - Google Chrome
Off-screen tabs are isolated from the user's normal browser experience. They do not show up in the browser window or tab strip, nor...
Read more >
chrome.tabCapture - Chrome Developers
Creates a stream ID to capture the target tab. Similar to chrome.tabCapture.capture() method, but returns a media stream ID, instead of a media...
Read more >
Chrome tabCapture example
lastError, it states "Invalid/Missing/Malformatted starting URL for off-screen tab." This is due to restrictions in Chromium's /chrome/browser/extensions/api/ ...
Read more >
[tabCapture] add a new getMediaStreamId method [chromium ...
M chrome/browser/extensions/api/tab_capture/tab_capture_api.cc ... getMediaStreamId() and getDisplayMedia() is still same as tabCapture.
Read more >
Getting Started with Chrome Ext Security from Zero(2)
capture( CaptureOptions options, function callback); getCapturedTabs — chrome.tabCapture.getCapturedTabs(function callback); captureOffscreenTab ...
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