How to open a link in chrome browser, even though the default computer browser is 'Safari'?

后端 未结 2 1761
再見小時候
再見小時候 2021-01-06 19:41

I\'ve built a chrome packaged app, and I\'m trying to make one of the buttons in it open the chrome browser in a specific link.

For this, I used window.open(\"

相关标签:
2条回答
  • 2021-01-06 20:08

    This only happens from inside the app window.

    If you call window.open from the background page, it will open in Chrome.

    So, send it to your background page:

    // app window
    function openInChrome(url) {
      chrome.runtime.sendMessage({action: "openURL", url: url});
    }
    
    // background
    chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {
      if(message.action == "openURL") window.open(message.url);
    });
    
    0 讨论(0)
  • 2021-01-06 20:10

    Use chrome.browser.openTab. See issue. At the moment it's in dev channel.

    0 讨论(0)
提交回复
热议问题