decodeAudioData issue in Chrome - react-native

I have some simple web react-native code that opens a local audio file and then prints the duration.
var reader = new FileReader();
reader.onload = function (event) {
var context = new AudioContext();
var data = event.target.result
context.decodeAudioData(data, function (buffer) {
console.log(buffer.duration);
});
};
reader.readAsArrayBuffer(files[0]);
files[0] has the type File
The code is working in Safari 15.6.1 but will not work in Chrome 108 for .aif filetypes. If I try to run in Chrome with the same local .aif audio file, I get the following error message:
DOMException: Failed to execute 'decodeAudioData' on
'BaseAudioContext': Unable to decode audio data
What causes Chrome to break with .aif file types and what's the fix?

AIFF filetype variants have not been supported on many browsers for a while (circa 2019). Chrome, Firefox and Edge definitely ceased support around that time or earlier.
As AIFF is an Apple media format it is still supported by Safari, macOS and iOS.
There maybe a possibility to use 3rd party libraries (like Aurora.js) to get browsers to download codecs to open the AIFF formats. Of course that would require permissions etc. by end user.

Related

Unable to close download notification(after successfully download) in mozilla firefox through selenium python 3

Selenium Version = 3.141,
Mozilla Firefox Version : 101.0.1
Automation Framework : Pytest
After successfully downloading the file, we want the notification to be closed.
I am able to download the file, but unable to perform any operation because of the notification that appears at the right top of the mozilla firefox browser. I want to close that notification through selenium code but it seems not working.
Have tried following solutions:
options = webdriver.FirefoxOptions()
# options = FirefoxProfile()
options.set_preference("dom.webnotifications.enabled", False)
options.set_preference("dom.push.enabled", False)
options.set_preference("browser.helperApps.neverAsk.saveToDisk","application/pptx, application/csv, application/ris, text/csv, image/png, application/pdf, text/html, text/plain, application/zip, application/x-zip, application/x-zip-compressed, application/download, application/octet-stream")
options.set_preference("browser.download.panel.shown", False)
options.set_preference("browser.download.folderList", 2)
options.set_preference("browser.download.manager.showWhenStarting", False)
options.set_preference("browser.download.dir", os.path.join(parent_folder, 'Downloads'))
options.set_preference("browser.download.manager.closeWhenDone", True)
options.set_preference("browser.download.manager.showAlertOnComplete", False)
# options.add_argument("--headless")
# options.headless = True
web_driver = webdriver.Firefox(firefox_options=options,executable_path=GeckoDriverManager().install())
Solution 2:
After successfully downloading the file, we are trying to press ESC key to dismiss the notification but this also seems not working
self.driver.find_element_by_tag_name('body').send_keys(Keys.CONTROL + Keys.ENTER)
OR
ActionChains(self.driver).send_keys(Keys.ESCAPE).perform()
Solution 3
Tried to Refresh the screen as well, but notification is still there.
Image is attached below:
File is being successfully downloaded but unable to close this notification through selenium python.
You are using the incorrect MIME type for pptx, so that may be causing the notification to hang around, so do following update to see if it resolves the issue:
from application/pptx
to application/vnd.openxmlformats-officedocument.presentationml.presentation
More info on MIME types can be found here: Common MIME types - HTTP | MDN
UPDATE
Mozilla has introduced changes from Firefox 97+, one of them is to the download panel and the behaviour is what you experienced. For selenium purposes, you can stop the panel from opening using the following option:
options.set_preference("browser.download.alwaysOpenPanel", False)

Loading Edge 83 with Selenium, in EdgeHTML mode (UseChromium = false). Returns Error

I'm trying to launch Edge using the EdgeHTML renderer mode, within Selenium, using Visual Studio C#.. I'm using the version 83.0.478.58 (64bit) and the driver 83.0.478.58 (64bit). Installed via nuget.
If I launch the browser using it works fine...
EdgeOptions options = new EdgeOptions();
options.UseChromium = true;
options.AddUserProfilePreference("download.default_directory", #"C:\temp\");
EdgeDriver edgeDriver = new EdgeDriver(options);
By default UseChromium is False, which should launch the browser in the EdgeHTML renderer. If I use the below code it will error out.
EdgeOptions options = new EdgeOptions();
options.AddUserProfilePreference("download.default_directory", #"C:\temp\");
EdgeDriver edgeDriver = new EdgeDriver(options);
The browser will open a new instance, but once the browser is open. The code bugs out and returns the error message,
OpenQA.Selenium.WebDriverException: 'The new session command returned a value ('Unknown error') that is not a valid JSON object.'
If I just try and simply initialise without the options, I still get the same error.
Anyone got any ideas? Looking around I see documentation and guides all over that launch the browser without UseChromium.
Cheers
Looks like you are trying to set the default download directory for the MS Edge legacy (EdgeHTML) browser using the Selenium code.
I want to inform you that it is possible to set the default download directory for the MS Edge (Chromium) browser as you had already tried that successfully but it is not possible to set the default download directory for the MS Edge legacy (EdgeHTML) browser using the Selenium code.
As a workaround, you can try to set the download directory manually.
References:
Change the default file download path for Edge using selenium
Change default download location in Edge

How to handle Window Based PDF

I've scenario like when clicking on one button its opening a Window Based PDF File:
I'm using Gecko driver Version -21.0 Firefox Version -61.0.1 Selenium Stand alone Server -3.13
I'm unable to switching to the window based PDF File getting error:
java.net.SocketException: Software caused connection abort: recv failed in Result
The above error is coming for "driver.getWindowHandles()" method
It's working for Chrome and IE but when I'm using Gecko driver Version - 20.1, I'm able to Switching the Window Based PDF.
Can anyone help me with this?
I want to handle it by using latest gecko driver -21.0
Unfortunately, it is difficult to perform operations on pdf by switching tabs. The best way is to download the pdf and perform operations on the downloaded file using some java library or pdf-parser.
This usual behaviour of pdf is due to an enabled feature of pdf js. Disabling that in the firefox profile may solve your issue
Update your Firefox profile solves this issue.
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference( "pdfjs.disabled", true );
profile.setPreference("pdfjs.disabled", true );
profile.setPreference("pdfjs.enabledCache.state", false );
profile.setPreference("pdfjs.enabledCache.state", false);
profile.setPreference("pdfjs.migrationVersion", 2);
profile.setPreference("pdfjs.previousHandler.alwaysAskBeforeHandling", true);
profile.setPreference("pdfjs.previousHandler.preferredAction", 4);
FirefoxOptions options = new FirefoxOptions().setProfile(profile);
WebDriver driver = new FirefoxDriver(options);
which stops the pdf opening in new window and further you can implement a method to download the file and parse the downloaded file.
Hope this helps you :)

Why in Opera the 'chrome_url_overrides' is not allowed for specified extension ID?

I am making a cross-browser extension, which overrides the standard "New Tab" page.
There is a manifest.json key for that, called chrome_url_overrides:
"chrome_url_overrides": { "newtab": "index.html" }
It works in Chrome and Firefox! But in Opera (45.0) the following error occurs when I try to load the extension:
'chrome_url_overrides' is not allowed for specified extension ID.
Based on what I've read in the MDN chrome_url_overrides docs, Opera supports that.
Now I'm not sure if Opera doesn't allow that in general, or if there is a way to activate it?
Edit: I found a similar, unanswered yet, 3-months-old thread in the Opera Forums.
Actually Opera now officially does not support chrome_url_overrides. A piece of evidence can be found on the MDN page that you referenced and it was confirmed by an Opera representative in their forum.
A potential workaround for achieving a new tab extension in Opera (actually this should work in other browsers too) is to use a background script with the following code:
const redirectURLS = [
"opera://startpage/",
"browser://startpage/",
"chrome://startpage/"
];
chrome.tabs.onCreated.addListener(function(tab) {
for (let i = 0; i < redirectURLS.length; i++) {
if (tab.url === redirectURLS[i]) break; // user is trying to open startpage
if (i == redirectURLS.length - 1) return; // Tab is not trying to open a startpage
}
chrome.tabs.update(tab.id, { url: "index.html" });
});
Having this will check if the user tries to open a new tab and if this is the case it will open the custom index.html page that came with installing the plugin instead. It's a hacky and dirty and not sure if it's going to be accepted by Opera but still, this may be a path of salvation for someone desperately trying to get a new tab extension live among the other Opera Addons.
Fun fact: Opera developed and distributed an addon which helps you install chrome extension from chrome extension store on Opera but the new tab extensions don't work and fail upon installation with the following message:
[Compatibility notice]
Please, be aware that this extension requires APIs that are not supported in Opera.
It still can work in Opera, so complete installation to verify.
Opera's Acceptance Criteria say that:
Extensions cannot replace Opera’s default start page.
Even if you manage to accomplish your aim and replace the standard "New Tab" page, then the extension will not pass moderation.
Workarounds include assigning a keyboard shortcut to open your page, or launching it from a browser action button.

Android apk download using Webdriver

I was trying to download the android apk file located at Hockey App share point but could only download a part of file not the complete file. Below is the code attached.
Below is the code that I have used to alter firefox configuration to handle the download pop-up
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("browser.download.folderList",2);
profile.setPreference("browser.download.manager.showWhenStarting",false);
// profile.setPreference("browser.download.dir", "Downloads");
profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/vnd.android.package-archive");// MIME type for apk file
WebDriver driver = new FirefoxDriver(profile);
Also, I tried using Content Type header("text/html; charset=utf-8") value shown in the Network monitor of Firefox. But that didn't work as well.
Any other approach other than Selenium is also appreciated.
Why don't you use the api provided by hockey app. Its pretty easy .. you can get the build url from available versions and then download. I have written a script pretty straightforward.
https://support.hockeyapp.net/kb/api
P.S. You should use the token from a developer account . Tester account doesnt get the build_url. But that shouldnt be difficult just ask for a read only token.