Download file with Playwright - playwright

How to download a file with Playwright?
I'm aware of this question
How to catch a download with playwright?
but that example code does not work. Using the latest released Playwright, there is no 'pageTarget' function on the browser instance:
const client = await browser.pageTarget(page).createCDPSession();

All the downloaded files belonging to the browser context are deleted when the browser context is closed. All downloaded files are deleted when the browser closes.
Download event is emitted once the download starts. Download path becomes available once download completes:
const [ download ] = await Promise.all([
page.waitForEvent('download'), // wait for download to start
page.click('a')
]);
// wait for download to complete
const path = await download.path();
...
https://github.com/microsoft/playwright/blob/master/docs/api.md#class-download

Playwright is going to support downloads in a cross-browser compatible way soon, you can track this feature request.
For now the above Chromium-specific snippet could be fixed by changing the line to:
const client = await context.newCDPSession(page);
which uses the new method for creating CDP sessions.

Related

Automated Recorded response to inbound call

I want to respond to an inbound voice call with a prerecorded message. Can this be done without using the Twilio API - ie similar to https://www.twilio.com/code-exchange/basic-voice-auto-response but my recording rather than a "robot" voice?
Here's the script to be placed in the "Functions and Assets" section of your console:
exports.handler = function (context, event, callback) {
const twiml = new Twilio.twiml.VoiceResponse();
twiml.play('https://filesamples.com/samples/audio/mp3/sample3.mp3');
callback(null, twiml);
};
Three options to host the file:
You can host it on a web server and replace the URL with the one to your file.
You could store the audio file on Twilio's servers.
Upload your file in "Functions and Assets" (click [Add+] > Upload File). Once uploaded, you will get the URL to put in the script by clicking "Copy URL."
Use "Assets (Classic)" to upload the file.

Use Mapbox with offline maps in Electron app

Is it possible to have an electron app showing offline map?
I downloaded the mbtiles and stored in the electron app, but I'm not able to show it in the angular side of the electron app.
I have the following code:
<mgl-map
class="map"
id = "map"
[style]="'mbtiles://assets/resources/downloaded.mbtiles'"
[center]="[mapCenter.longitude, mapCenter.latitude]"
(load) = "onLoad($event)"
(dragEnd)="mapDrag()"
[doubleClickZoom]="false"
[bearing]="[bearing]"
[zoom]="[zoom]"
[pitch]="[pitch]">
</mgl-map>
But I get the error
zone-evergreen.js:1068 Fetch API cannot load mbtiles://User/hello/path/to/file.mbtiles. URL scheme "mbtiles" is not supported.
So, in order to make it works in an online way I have to change the style for
[style]="'mapbox://styles/mapbox/streets-v9'"
Is it possible to make it works serving the mbtiles from the nodejs code or in other way?
To serve up your local mbtiles file, you need to register the mbtiles protocol in main.js. Something like this should do it:
const electron = require('electron');
const protocol = electron.protocol;
const path = require('path');
protocol.registerHttpProtocol('mbtiles', (req, cb) => {
const url = 'assets/resources/downloaded.mbtiles';
cb({ path: path.normalize(`${__dirname}/${url}`) })
});
You can read up on protocol handlers in electron here: https://www.electronjs.org/docs/api/protocol#protocol

Flutter/Dart SocketException Uploading Video File to URL

I am recieving this error message when attempting to upload a video file to the speicified URL:
DioError (DioError [DioErrorType.DEFAULT]: SocketException: OS Error: Connection reset by peer, errno = 54, address = storage.googleapis.com, port = 64995)
Note: It is a DioError as I am using the dio Dart/Flutter package: https://pub.dev/packages/dio I recieve the error using equivilent API such as the http library.
Code to upload the video file selected from storage:
//File videoFile...
FormData data = FormData.fromMap({
"videoFile": await MultipartFile.fromFile(videoFile.path),
});
Response response = await Dio().post(
directUpload.url,
data: data,
onSendProgress: (int sent, int total) {
print("$sent $total");
},
);
The URL (directUpload.url) is one generated from and provided by the Mux API to their Google Cloud Storage.
https://storage.googleapis.com/video-storage-us-east1-uploads/...
When post is called, a small amount is uploaded (e.g. 655524 / 17840042) and then the error occurs. The test video is 17.8 Mb in size.
Running this on an iOS device or the iOS simulator produces the same result/error.
I have tried: flutter clean, flutter upgrade, deleteing Podfile and pod repo update, deleting the app from device. All to no avail.
Change from a POST to a PUT request resolves the issue.
yes, I have same problem with Dio.
current can't upload data type Uint8List
My temporary solution:
use http lib
http: ^0.12.1
import 'package:http/http.dart' as http;
Future uploadData(Uint8List imageData) async {
await http.put(preData.url, headers: getHeader(), body: imageData);
}
use:
List<int> imageData = File(filePath).readAsBytesSync();
await uploadData(imageData);
hope to help you
The error message "Connection reset by peer" appears, if the web services client was waiting for a SOAP response from the remote web services provider and the connection was closed prematurely.
One of the most common causes for this error is a firewall in the middle closing the connection. In this case you could increase the connection timeout in the firewall.You can find the component that closes the connection by capturing and analyzing an IP trace.
Other possible causes are e.g.:
resource limitations on the server side like out of memory server
process killed
overload on the server due to a high amount of traffic
ALSO Try this..
cd ~/flutter
git checkout -b max-in-flight
code packages/flutter_tools/lib/src/devfs.dart # edit kMaxInFlight from 6 to 1
rm bin/cache/flutter_tools*
AND This
flutter clean
flutter channel stable
have you tried using http.MultipartRequest method ?
As it can be used to transfer large files, you can also try is DIO alternative if present in dio
and how to use http.MultipartRequest here is an article https://dev.to/carminezacc/advanced-flutter-networking-part-1-uploading-a-file-to-a-rest-api-from-flutter-using-a-multi-part-form-data-post-request-2ekm
let me know if it works or not.
When post is called, a small amount is uploaded (e.g. 655524 / 17840042) and then the error occurs. The test video is 17.8 Mb in size.
Answer-
Go your cpanel MultiPHP INI Editor file and increase post_max_size
No need to change u r flutter code, it is right .

Fetch/XHR own files

My extension works in Chrome, Firefox, and Opera. I wanted to support edge too. However I cannot do a simple thing, I cannot fetch/XHR my own files! I even added <all_urls> to my permissions array in manifest.json, however I keep getting TypeMismatchError and in details it says "Permission Denied". Here is a screenshot:
Does anyone know if it is possible to fetch your own files in Edge? I need to specifically fetch the messages.json files in my /_locales/* folders.
This is a known issue which has been reported here https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/8546263/, you can use the workaround mentioned in the link or use XMLHttpRequest instead of fetch.
const xhr = new XMLHttpRequest();
xhr.onload = () => {
console.log(xhr.responseText);
};
const url = chrome.runtime.getURL('test/test.js');
xhr.open("GET", url);
xhr.send();

Reading File on Google Drive using Dart

I created a configuration file (Simple Text File) on my Google Drive and now I would like to read it from my Chrome Packaged Dart Application. But I'm not able to get more information of the file than it's name, size etc.
For accessing Google Drive I use the google_drive_v2_api.
Any suggestion on how to get the contents of my configuration file would be great! Thanks!
I just did some test in my own chrome app, uploading and downloading a simple file:
chrome.identity.getAuthToken(new chrome.TokenDetails(interactive: true ))
.then((token){
OAuth2 auth = new SimpleOAuth2(token);
var drive = new gdrive.Drive(auth)..makeAuthRequests=true;
drive.files.insert({},content:window.btoa('hello drive!')).then((sentMeta){
print("File sent! Now retrieving...");
drive.files.get(sentMeta.id).then((repliedMeta){
HttpRequest request = new HttpRequest()..open('GET', repliedMeta.downloadUrl)
..onLoad.listen((r)=>print('here is the result:'+r.target.responseText));
auth.authenticate(request).then((oAuthReq)=>oAuthReq.send());
});
});
});
It works, but the HttpRequest to get content back seems heavy...
But i really recommend you to a take look to chrome.storage.sync if your config file size is < to 4ko... If not, you could also use the chrome SyncFileSystem API... They are both easier to use, and SyncFileSystem use Drive as backend.
This page on downloading files talks through the process for getting the contents of a file.

Resources