Google Chrome Socket API in extensions

2019-01-11 14:17发布

问题:

So after developing an extension for a few hours, assuming that the chrome.socket API would be available to extensions, I load in my extension and I'm told that the Socket API is only available for 'Packaged Apps'.

Does anyone know what's happening, and whether extensions will get the feature (back, since I think they had access when it was in .experimental)?

回答1:

From the Chrome docs:

Packaged apps can act as a network client for TCP and UDP connections.

No, extensions do not have access to the socket API, and they aren't likely to ever get it.

Your confusion is understandable, since what Google called "packaged apps" used to be nothing but glorified extensions with an icon on the home screen. However, Google is now driving a much wider divide between extensions and apps.

Extensions used to have a subset of the functionality the apps did, but now there is mutually exclusive functionality in each. Extensions are meant for enhancing normal Web browsing, whereas apps are meant to be used as stand-alone tools that do not interfere with normal browsing. If you look at the API lists for apps and for extensions, you'll see that the list is vastly different: apps have the powerful hardware- and OS-centric APIs like socket, usb, and bluetooth, while extensions have a monopoly on browser-centric APIs like tabs, cookies, and bookmarks.