Closed Bug 1303609 Opened 8 years ago Closed 8 years ago

[e10s] contentDocumentAsCPOW use in extension cause script to never finish.

Categories

(Firefox :: Tabbed Browser, defect)

defect
Not set
normal

Tracking

()

RESOLVED INVALID

People

(Reporter: jya, Unassigned)

References

Details

Working on finding out why the about:media extension doesn't work (bug 1282041).

Source code is available there:
https://github.com/jyavenard/aboutmedia/blob/master/src/chrome/content/aboutmedia.xhtml

Consider this code:

<?xml version="1.0"?>

<!-- This Source Code Form is subject to the terms of the Mozilla Public
   - License, v. 2.0. If a copy of the MPL was not distributed with this
   - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>about:media</title>
    <meta name="viewport" content="width=device-width"/>
  </head>
  <body><h1>HTMLMediaElement debug data</h1><pre id='data'></pre></body>
<script type="application/javascript">
<![CDATA[
var entityMap = {
  "&": "&amp;",
  "<": "&lt;",
  ">": "&gt;",
  '"': '&quot;',
  "'": '&#39;',
  "/": '&#x2F;'
};

function escapeHTML(string) {
  return String(string).replace(/[&<>"'\/]/g, function (s) {
    return entityMap[s];
  });
}

var qi1 = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor);
var qi2 = qi1.getInterface(Components.interfaces.nsIWebNavigation);
var qi3 = qi2.QueryInterface(Components.interfaces.nsIDocShellTreeItem);
var qi4 = qi3.rootTreeItem;
var qi5 = qi4.QueryInterface(Components.interfaces.nsIInterfaceRequestor);
var qi6 = qi5.getInterface(Components.interfaces.nsIDOMWindow);
var mainWindow = qi6;

var tabbrowser = mainWindow.gBrowser;
var text = "numtab=" + tabbrowser.browsers.length + "\n";
var found = false;
for(var i=0; i < tabbrowser.browsers.length; ++i) {
  var b = tabbrowser.getBrowserAtIndex(i);
  var videos = b.contentDocumentAsCPOW.querySelectorAll('video');
  text += "length[" + i + "]=" + videos.length + "\n";
}
document.getElementById('data').innerHTML = text;
]]>
</script>

</html>

This looks for the window with a video element in it. With e10s disabled, it will show something like:
HTMLMediaElement debug data

numtab=2
length[0]=0
length[1]=1

However, when e10s is enabled, it just shows a blank page.

Attempting to use the JS debugger it shows that 
b.contentDocumentAsCPOW never returns (though it doesn't block or anything, it only appears that the JS code never completes.

Now I'm not sure if contentDocumentAsCPOW is still supported or not, I see references on attempt to remove its use from the chrome/xul code ; but in the mean time I know of no other way to do what about:media does.

I'm not entirely sure on which component this should fit into.
Component: DOM → Tabbed Browser
Product: Core → Firefox
(In reply to Jean-Yves Avenard [:jya] from comment #0)
> Attempting to use the JS debugger it shows that 
> b.contentDocumentAsCPOW never returns (though it doesn't block or anything,
> it only appears that the JS code never completes.

Does it perhaps throw? A try catch with logging seems like much the easiest way of figuring that out.
Flags: needinfo?(jyavenard)
FWIW, I don't know if/how the content page debugger would deal with CPOWs... I wouldn't be surprised if the answer is "it doesn't", so I'd use logging rather than the debugger to figure out what does/doesn't execute.
changing the main loop for:
var tabbrowser = mainWindow.gBrowser;
var text = "numtab=" + tabbrowser.browsers.length + "\n";
console.log(text);
var found = false;
for(var i=0; i < tabbrowser.browsers.length; ++i) {
  console.log("starting loop:" + i);
  let b = tabbrowser.getBrowserAtIndex(i);
  console.log("processing tabbrowser[" + i + "]");
  try {
  	let videos = b.contentDocumentAsCPOW.querySelectorAll('video');
	  text += "length[" + i + "]=" + videos.length + "\n";
  } catch(err) { 
  	console.log("error[" + i + "]:" + err.message);
  }
  console.log("continuing loop:" + i);
}
document.getElementById('data').innerHTML = text;

shows in the console:
umtab=4
  media:40:1
starting loop:0  media:43:3
processing tabbrowser[0]  media:45:3
error[0]:unsafe CPOW usage forbidden  media:50:4
continuing loop:0  media:52:3
starting loop:1  media:43:3
processing tabbrowser[1]  media:45:3
error[1]:unsafe CPOW usage forbidden  media:50:4
continuing loop:1  media:52:3
starting loop:2  media:43:3
processing tabbrowser[2]  media:45:3
continuing loop:2  media:52:3
starting loop:3  media:43:3
processing tabbrowser[3]  media:45:3
continuing loop:3

There are 4 tabs, the first two are showing normal https URL, the last two are the extension page and about:extensions ; those last two don't throw the exception which is kind of normal I guess...

hmmm...

So that puts me back to how do I retrieve the content of other tabs..
Flags: needinfo?(jyavenard)
guess i have to learn about frameScript.
Status: NEW → RESOLVED
Closed: 8 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.