开发者

Differences in Chrome on various OS

I'm developing a chrome extension and i've met a very strange bug - my code works well on Mac OS, but doesn't work on Windows and Linux versions of Chrome. Versions are the same.

function captureAllScreen() {
  chrome.windows.getCurrent(function(w) {
    chrome.tabs.captureVisibleTab(w.id, {"format":"png"}, function(response) {
      var image = response;
      var url;
      chrome.tabs.getSelected(w.id, function(response) {
        url = response.url;
      });

      var viewTabUrl = [chrome.extension.getURL('app.html'),
                         '?id=', id++].join('');

      chrome.tabs.create({url: viewTabUrl}, function(tab) {
        var targetId = tab.id;
        var addSnapshotImageToTab = function(tabId, changedProps, tab) {
          if (tabId != targetId || changedProps.status != "complete") {
            return;
          };
          chrome.tabs.onUpdated.removeListener(addSnapshotImageToTab);
          var views = chrome.extension.getViews();
          for (var i = 0; i < views.length; i++) {
            var view = views[i];
            if (view.location.href == viewTabUrl) {
              view.twm_Draw.sendScreen(image, url); //Application-specific method
              break;
            }
          }
          window.close();
        };
        chrome.tabs.onUpdated.addListener(addSnapshotImageToTab);
      });
    });
  });
};

Update: What i want to do with this code - is to take a screenshot and tab url and send it to my extension's page. When user 开发者_Go百科clicks on my extension's icon - it opens a popup with two buttons, one of it fires this function.

In Mac Os everything works - this code takes a screenshot, tab url, opens new tab with my application and sends the data there. On Linux & Windows versions of chrome it doesn't send the data, after clicking the icon in the popup you just get a blank tab opened.


I think this part might be causing problems:

var url;
chrome.tabs.getSelected(w.id, function(response) {
  url = response.url;
});

//using url

The rest of the code should be wrapped into callback function, otherwise order of execution is not guaranteed.


I'm guess it's only supported on Mac, whatever it does:

view.twm_Draw.sendScreen(image, url); //Application-specific method

I don't know about Unix but on Windows you can only get a screenshot using a NPAPI plugin like the Google extension for screen capture.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜