I'm trying to customize my own chrome://inspect/#devices , I see it uses utils.js and inspect.js and at the same time it uses a global "chrome" object in the original ones, how do I invoke it from my own inspect.js? Right know I just have a local clone:
Clone folder of chrome://inspect/#devices
devices.html
inspect.js
util.js
jquery.js
So I load devices.html but is not working, and the first obstacle I have is that global object "chrome" is not available for inspect.js.
I found a somehow related thread Can `chrome.*` extension API's be used inside content scripts?
chrome://inspect is one of the build-in Chrome pages (all are listed here - chrome://about/). These pages are considered an integral part of the browser and they have access to special actions (via chrome object). Browser will not inject chrome object into the regular pages (such as your copy of the inspect page).
Unfortunately, you won't be able to modify chrome://inspect page (even with an extension as you can't inject scripts into chrome:// pages). However, you might be able to recreate that page in an extension using debugger API.
Related
I have created an unpacked plugin for Chrome (that also works in Firefox), that has a single script.js file. And it works.
However, trying to call a function included in the addon's script.js file from the console results in:
Uncaught ReferenceError: _islet_convert is not defined
at <anonymous>:1:1
(anonymous) # VM259:1
Which by the way I tested just to verify with not_a_function() in the console, and the error was the same.
Can someone tell me how Chrome and probably Firefox handles or isolates the JavaScript in the content_scripts files? And if there is any way to reference a function/method in the file.
From the documentation in Chrome:
https://developer.chrome.com/docs/extensions/mv2/content_scripts/
Content scripts live in an isolated world, allowing a content script to makes changes to its JavaScript environment without conflicting with the page or additional content scripts.
...
Isolated worlds do not allow for content scripts, the extension, and the web page to access any variables or functions created by the others. This also gives content scripts the ability to enable functionality that should not be accessible to the web page.
Essentially, it appears any communication needs to happen through the DOM including adding event listeners.
Example, qbittorent can be made to open links that are of torrent files.
Email clients mailto:
Is it possible to create links in a browser that will open the given file in Intellij? (Not full path, but entire package possibly ).
Idea is that this will be created for bitbucket.
There is an open feature request to add idea:// protocol handler.
At the moment it works on macOS only out of the box. For other platforms you can try the third-party solution or other workarounds from the ticket comments.
There is also a built-in web server providing the REST API to open files.
It will work with the relative paths only when the IDE is already running and the project is open: http://localhost:63342/api/file/relative/to/module/root/path/to/file.kt.
With the JetBrains Toolbox App installed one will be able to use jetbrains:// protocol for navigation, it's work in progress and should be available in 2019.2.
See JBProtocolNavigateCommand.kt for the reference:
// handles URLs of the following types:
// jetbrains://idea/navigate/reference?project=IDEA
// [&reference[X]=com.intellij.navigation.JBProtocolNavigateCommand[.perform][#perform]]+
// [&path[X]=com/intellij/openapi/project/impl/JBProtocolNavigateCommand.kt[:23[:1]]]+
// [&selection[X]=25:5-26:6]+
Sample URL:
jetbrains://idea/navigate/reference?project=IDEA&fqn=com.intellij.openapi.application.JetBrainsProtocolHandler#getParameters
Toolbox URL matches regexp:
"${JetBrainsProtocolHandler.PROTOCOL}([\\w\\-]+)/navigate/reference\\?project=(?<project>[\\w]+)(&fqn[\\d]*=(?<fqn>[\\w.\\-#]+))*(&path[\\d]*=(?<path>[\\w-_/\\\\.]+)(:(?<location1>[\\d]+))?(:(?<location2>[\\d]+))?)*(&selection[\\d]*=(?<line1>[\\d]+):(?<column1>[\\d]+)-(?<line2>[\\d]+):(?<column2>[\\d]+))*"
There will be also UI for copying TBX protocol URLs directly from the editor similar to the Copy Reference action in the context menu. The same will work for IDE settings navigation.
As an update to #CrazyCoder's answer
This works* on Mac currently. (unable to test on anything else personally)
* There are some issues:
There is no context menu option for generating this link from clicking on a line of code
The keybinding (see below) generates the incorrect path, and it needs to be modified manually by either changing the sources root temporarily, or typing the missing path parts by hand.
There is a keybinding you can use to generate the url, under Preferences > Keymap > Copy Path/Reference > Toolbox URL. Note that the cursor location when using the keybinding matters. From what I can tell, if the cursor is at the beginning or end of a line, it generates a url with &path=..., else it generates with &fqn=.... The fqn option will often link to the wrong area of the code, especially when interfaces, libraries, auto-wiring, or anything not a direct vanilla class/object/function is attempted to link to.
I have filed an issue with more details on the broken path generated by the keybinding: https://youtrack.jetbrains.com/issue/IDEA-290640
Chrome had introduced the use of extensions for WebRTC Screen Sharing. In this, each domain has to have the extension so that people install the extension in order to share the screen using webrtc.
Here is my use case:
During an on-going webrtc video call, if one person needs to do screen sharing and doesn't have the extension then after installing the extension one is required to refresh the page. This interrupts the call and both people need to join the call again.
I want to control the user experience using javascript so that refresh is not required. But if we don't do refresh, html page doesn't recognize the recently installed extension.
I have seen many open source code regarding this but none of them has use case similar to mine. They assume the extension to be installed during the session.
However, I had seen www.uberconference.com and they have similar use case. I tried installing the screen sharing extension during a live call and it did not require the page refresh and did not interrupt the call. It did the screen sharing right after extension was installed.
I could not understand how they did it as uber is not open source. Many people say that refresh is must after installing the extension. Any help in this case will be highly appreciated.
Here is how I install the chrome extension using in-line installation:
$scope.installExtension= function(){
!!navigator.webkitGetUserMedia
&& !!window.chrome
&& !!chrome.webstore
&& !!chrome.webstore.install &&
chrome.webstore.install('https://chrome.google.com/webstore/detail/<some-id>',
successInstallCallback,
failureInstallCallback
);
};
function successInstallCallback() {
//location.reload();
}
function failureInstallCallback(error) {
alert(error);
}
This is something we recently changed in getScreenMedia. View the pull request to see how we did it:
I wrote about the changes on my blog, so look there for more details, but the important bits are:
Instead of creating a communication channel on chrome.runtime.connect, and messaging directly, we can use external messaging. Instead of posting a message to the window, which gets picked up by the content script and passed to the background script (and vice versa), we can use chrome.runtime.sendMessage(extensionId, options, callback) and, in the background script chrome.runtime.onMessageExternal. This works where the other solution doesn't, because background scripts are loaded immediately upon extension installation, whereas content scripts are injected on page load.
So, basically, the extension uses a different permission:
"externally_connectable": {
"matches": [
"https://example.com/*"
]
}
And a different API:
chrome.runtime.sendMessage combined with chrome.runtime.onMessageExternal
instead of
window.postMessage combined with window.addEventListener('message') and chrome.runtime.connect.
At least two different sites https://apps.mypurecloud.com and https://beta.talky.io do screen sharing with inline extension installation with no reload at all.
This may helps today. If you are running Janus demos on the localhost - just run it over https.
If you will run it over http : the getDisplayMedia function will not be declared (e.g. in Chrome), and then Janus will ask you for plugin install.
If you had installed your own Janus-server: to use https - you must to configure ssl-certificates in Janus server configs:
janus.transport.http.jcfg - if you're using https in server definition
janus.transport.websockets.jcfg - if you're using wss (and don't forget to enable secure web-socket in it)
Have you looked at Chrome Extension Inline Installation ...
https://developer.chrome.com/webstore/inline_installation
I was having the same problems until I put within the html <head> tag ...
<link rel="chrome-webstore-item" href="https://chrome.google.com/webstore/detail/[your-chrome-extension-id]" >
Your extension manifest also needs to include the domain that this head tag is on.
I'm trying to use the new chrome inline install feature for extensions (see here: http://code.google.com/chrome/webstore/docs/inline_installation.html).
I can't get it to work unfortunately, and have very little clues to go by. I've added the link element to the head element
<link rel="chrome-webstore-item" href="https://chrome.google.com/webstore/detail/pnnfemgpilpdaojpnkjdgfgbnnjojfik">
and I call
chrome.webstore.install();
in a jquery event handler. I've also verified my domain, however, I'm testing this on a local machine but have a subdomain pointed to my localhost (i.e. testing on dev.getbentobox.com which is mapped to localhost in my hosts file if that makes a difference).
When stepping through my js using the chrome debugger, chrome.webstore.install() is getting called and the function is defined. However, nothing happens - no install, no javascript exception, no console printing, nothing.
any ideas?
Your Chrome Web Store item doesn't show the verified site. If you compare it to the "We Heart It" extension, which can be inline installed from http://weheartit.com/heart-button, it has a green check saying "from weheartit.com". You'll need to edit your Web Store item, and associate your verified site with the item.
As of December 2018 (Chrome version 71), Google has disabled this feature. The workaround is to send the user to your extension in the Chrome Web Store.
Source: https://developer.chrome.com/extensions/inline_faq#change_dec18
What will change in M71 (Dec 2018)?
Beginning in M71, Chrome will no longer support the chrome.webstore.install() method and calling it will fail, resulting in a broken installation flow on your site. At this point calls to the API will throw a JavaScript TypeError. You should remove any calls to the API method before this date.
Hey I got a quick question:
I have got a chrome extension that adds a popup page to the toolbar. It accepts input from the user then calls a NPAPI dll which generates an XML file. I would like to be able to, after the NPAPI dll finishes its work, create a new tab which would open to the newly generated XML page.
Can anyone help me out with this?
Thanks.
You can let your NPAPI communicate to JavaScript via NPN_Invoke. NPN_Invoke will allow you to invoke a method on a given NPObject.
For example, you can construct your method NPN_GetStringIdentifier, and use that to execute a method in your popup.
You can refer to this article, on how to communicate back to JavaScript from NPAPI plugin. The example shown there is a simple console.debug("Hello from C++")
Update
I noticed you want to open the xml file right after. Did you save the XML file in the location of the extension folder?
C:\Users\[user]\AppData\Local\Google\Chrome\User Data\Default\Extensions\[extension_id]\[extension_version]
Then you can open it with chrome.extension.getURL([file]);
But, it would be great if you return the XML file and open it within the extension itself.
Ideally you don't put the logic for UI behavior into the plugin, but in the extension. The plugin should tell the extension where the XML file is located and the extension should handle the rest.
This could be done two ways:
Synchronously returning the location is easy: You do the work directly from the Invoke() implementation of your plugin and return a string containing the location of the file to the script.
This of course has the downside of blocking the main- (and GUI-)thread until processing is done and thus is no option when processing is not done quickly.
Asynchronously returning it is a bit more work: Ideally you allow the extension to specify a callback function that should be invoked when processing is done. This could be achieved by either handling addEventListener() accordingly or by allowing the script to pass a callback as a parameter when it initiates the XML processing. The XML processing function then starts or feeds another thread doing the actual work and returns immediately. When the processing is done you call NPN_InvokeDefault() on the stored function object to call it.
Beware: Calling into JavaScript always has to be done on the main thread.