Skip to content

Commit

Permalink
Revert change in jsHandle.uploadFile (#100)
Browse files Browse the repository at this point in the history
  • Loading branch information
xvrh committed Jan 8, 2020
1 parent bbffca7 commit 9dafdd8
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 30 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

# 1.15.1 (2020-01-08)
- Expose `ClientError` class
- (internal) Revert previous change in `jsHandle.uploadFile`

# 1.15.0 (2019-12-27)
- Add element.select and element.evaluate for consistency
- Prepare jsHandle.uploadFile for CDP Page.handleFileChooser removal
Expand Down
4 changes: 2 additions & 2 deletions doc/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -3451,8 +3451,8 @@ await handle.select(['blue']); // single selection
await handle.select(['red', 'green', 'blue']); // multiple selections
```

Parameters
- -Values of options to select. If the `<select>`
Parameters:
- `values`: Values of options to select. If the `<select>`
has the `multiple` attribute, all values are considered, otherwise only
the first one is taken into account.

Expand Down
1 change: 1 addition & 0 deletions lib/puppeteer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export 'src/page/mouse.dart' show MouseButton;
export 'src/page/network_manager.dart' show Request, Response;
export 'src/page/page.dart'
show
ClientError,
Page,
PdfMargins,
PaperFormat,
Expand Down
31 changes: 5 additions & 26 deletions lib/src/page/js_handle.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import 'dart:convert';
import 'dart:io';
import 'dart:math';
import 'package:mime/mime.dart';
import 'package:path/path.dart' as p;
import '../../protocol/dom.dart';
import '../../protocol/runtime.dart';
import '../connection.dart';
Expand Down Expand Up @@ -362,8 +359,8 @@ async function _(element, pageJavascriptEnabled) {
/// await handle.select(['red', 'green', 'blue']); // multiple selections
/// ```
///
/// Parameters
/// - -Values of options to select. If the `<select>`
/// Parameters:
/// - `values`: Values of options to select. If the `<select>`
/// has the `multiple` attribute, all values are considered, otherwise only
/// the first one is taken into account.
///
Expand All @@ -390,27 +387,9 @@ async function _(element, pageJavascriptEnabled) {
///
/// Sets the value of the file input these paths.
Future<void> uploadFile(List<File> files) async {
var filesArg = [];
for (var file in files) {
var fileArg = <String, String>{
'name': p.basename(file.path),
'content': base64.encode(await file.readAsBytes()),
'mimeType': lookupMimeType(file.path),
};
filesArg.add(fileArg);
}
await evaluateHandle(
//language=js
r'''async(element, files) => {
const dt = new DataTransfer();
for (const item of files) {
const response = await fetch(`data:${item.mimeType};base64,${item.content}`);
const file = new File([await response.blob()], item.name);
dt.items.add(file);
}
element.files = dt.files;
element.dispatchEvent(new Event('input', { bubbles: true }));
}''', args: [filesArg]);
await executionContext.domApi.setFileInputFiles(
files.map((file) => file.absolute.path).toList(),
objectId: remoteObject.objectId);
}

/// This method scrolls element into view if needed, and then uses [touchscreen.tap]
Expand Down
3 changes: 1 addition & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: puppeteer
description: A high-level API to control headless Chrome over the DevTools Protocol. This is a port of Puppeteer in Dart.
version: 1.15.0
version: 1.15.1
homepage: https://github.com/xvrh/puppeteer-dart

environment:
Expand All @@ -13,7 +13,6 @@ dependencies:
http: '>=0.9.0 <0.13.0'
logging: ^0.11.3
meta: ^1.1.1
mime: ^0.9.0
path: '>=1.0.0 <2.0.0'
petitparser: '>=2.2.0 <3.0.0'
pool: ^1.4.0
Expand Down

0 comments on commit 9dafdd8

Please sign in to comment.