I am making a Chrome Extension in which the microphone keeps listening all the time in lifetime of a Chrome Window.
I am trying to include audioCapture in permissions in manifest.json,
But I get the error:
audioCapture' is only allowed for packaged apps, but this is a extension
What can I do in this?
Is there any other way through which mic keeps listening?
I guess you can use getUserMedia() in content js file or if you want to get permission in manifest.json, try packaging your app and then load it again
'audioCapture' permission isn't supported yet for Chrome extensions manifest (see chrome extension documentation for the complete list).
You can trigger it in your content js files or in popup.js calling getUserMedia promise like this:
console.log('try trigger authorization');
navigator.mediaDevices.getUserMedia({ audio: true, video: false })
.then((mediaStream) => {
//in promise will be triggered user permission request
})
.catch((error) => {
//manage error
});
This workaround works fine for my purpose.
Related
I'm testing out some audio worklet code by loading an example module from Github via AudioWorklet.addModule(githubUrl). However when I look at the network tab in developer settings I don't see a network request to Github. I know that it is making the request because it was giving a CORS error before I switched to using raw.githubusercontent address (now it is giving Uncaught (in promise) DOMException: The user aborted a request). I want to be able to inspect what the network call is returning so I can help diagnose the problem.
There seems to be a bug in Chrome which prevents the network request from being shown in the dev tools. I think it would be a good idea to file a bug for that.
For now you could just use Firefox. It shows the network request in the dev tools.
If you want to keep using Chrome you can proxy your request with fetch() to make it appear in the devtools.
Instead of calling addModule() directly ...
context.audioWorklet.addModule(url)
... you could fetch the source first and then wrap it into an object URL.
fetch(url)
.then((response) => response.text())
.then((text) => {
const blob = new Blob([text], { type: 'application/javascript; charset=utf-8' });
const objectUrl = URL.createObjectURL(blob);
return context.audioWorklet.addModule(objectUrl)
.finally(() => URL.revokeObjectURL(objectUrl));
})
I'm developing an extension for Google Chrome and I'm monitoring HTTP requests. In the event handler for chrome.webRequest.onHeadersReceived I'm trying to make a delay. It cannot wait asynchronously (unlike WebExtensions in Firefox) and it doesn't support something like Thread.Sleep or CriticalSection or ResetEvent or anything. The only solution that I see is spin waiting which is a very bad choice. Even synchronous XMLHTTPRequest is deprecated and doesn't work.
var headersReceived = function (e) {
/// ?????? some method to delay synchronously
return {cancel: false};
};
chrome.webRequest.onHeadersReceived.addListener(headersReceived,
{urls: ["*://*/*"]},
["blocking", "responseHeaders"]);
You can try and reference to this plugin: network-spinner-devtool it is a browser devtools extension, with capacity of URL level configuration and control, to allow introducing delay before sending http request or after receiving response(support in firefox only).
it supports both Chrome and Firefox browser
Can install from Chrome web store as well Chrome DevTools
I'd like to use the Chrome off-screen tab capture API in my extension. So, I worked up a manifest with the tabCapture permission, and some code to try it out:
chrome.tabCapture.captureOffscreenTab('http://example.com', {
audio: true,
video: true
}, function () {
console.log(arguments);
});
Unfortunately, I get this error on my console:
Unchecked runtime.lastError while running tabCapture.captureOffscreenTab: Extension is not whitelisted for use of the unstable, in-development chrome.tabCapture.captureOffscreenTab API.
How can I whitelist my extension?
I found a bug report where there was an ask to use _api_features.json rather than hard-coded extension IDs, but I couldn't find that file.
#wOxxOm answered this question!
Snag the ID of the extension on chrome://extensions. Run Chrome like so:
chrome.exe --whitelisted-extension-id=abcdefghijklmnopqrstuvwxyz
It works great!
The following code supposes to open a URL in an external app:
var a = document.createElement('a');
a.href = 'myprotocol:jdoe#example.com;fromuser=John%20Doe;mode=audiovideo';
document.body.appendChild(a);
a.click();
When the app is not installed, on some PCs Chrome fails silently while on the others it displays this window:
Where is this behavior defined?
Application association to URI Schema
If you want to register your app to handle a specific URI Schema in Windows, then you should register it in registry. It is explained in MSDN article and Googling "Registering an Application to a URI Scheme" gives plenty of examples.
HKEY_CLASSES_ROOT/
your-protocol-name/
(Default) "URL:your-protocol-name Protocol"
URL Protocol ""
shell/
open/
command/
(Default) PathToExecutable
Web App schema registration
You can register a custom protocol handler with Google Chrome using navigator.registerProtocolHandler (Firefox has the feature too).
navigator.registerProtocolHandler(
'web+mystuff', 'http://example.com/rph?q=%s', 'My App');
Please note, that your protocol has to start with web+. Otherwise you would get SECURITY_ERR: DOM Exception 18 error.
Or, if you are developing a Chrome App, then you can register your handlers in your manifest file.
"url_handlers": {
"view_foo_presentation": {
"matches": [
"https://www.foo.com/presentation/view/*"
],
"title": "View Foo presentation"
}
}
You can also look into the Chrome URLs (chrome://chrome-urls/) and see if you can change it in any of the settings.
I'm running the following code in a background.js script for my Chrome extension:
chrome.browserAction.onClicked.addListener(captureCurrentTab());
function handleCapture(stream) {
console.log('content captured');
console.log("backround.js stream: ", stream);
alert(stream);
// localStream = stream; // used by RTCPeerConnection addStream();
// initialize(); // start signalling and peer connection process
}
function captureCurrentTab() {
console.log('reqeusted current tab');
chrome.tabs.query({active : true}, function(tab) {
console.log('got current tab');
chrome.tabCapture.capture({
audio : true,
video : false
}, handleCapture);
});
}
However, this gives me the following error:
Unchecked runtime.lastError while running tabCapture.capture: Extension has not been invoked for the current page (see activeTab permission). Chrome pages cannot be captured.
However, I specifically am granting activeTab permission in manifest.json:
"permissions": [
"tabs",
"tabCapture",
"activeTab",
]
Thanks for your help!
When the activeTab permission is declared, you only get access to the current tab when a user performs certain actions that imply they want you to have access.
The following user gestures enable activeTab:
Executing a browser action
Executing a page action
Executing a context menu item
Executing a keyboard shortcut from the commands API
Accepting a suggestion from the omnibox API
The error is telling you that capture the current tab because the user hasn't performed one of the actions listed above.
It looks like you might already understand this and just have an error in your code. When registering captureCurrentTab as the click listener for the browser action, you are actually executing it immediately instead of passing the function by reference. Change your first line to this:
// Remove the () after captureCurrentTab
chrome.browserAction.onClicked.addListener(captureCurrentTab);
Chrome pages cannot be captured. means that you are trying to capture a chrome://, chrome-extension://, or similar Chrome specific page which is not allowed. Make sure the current page is http:// or https://.