Skip to content

Commit

Permalink
#1035 - add-on to persist download location
Browse files Browse the repository at this point in the history
  • Loading branch information
kensoh committed Jun 8, 2021
1 parent 4e99629 commit 04ef454
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/tagui_header.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ var r_count = 0; var py_count = 0; var sikuli_count = 0; var chrome_id = 0;
// chrome context for frame handling and targetid for popup handling
var chrome_context = 'document'; var chrome_targetid = '';

// to track download path if set by user using 'download to location' step
var download_path = '';

// variables to track frame offset if current context is within a frame
var frame_step_offset_x = 0; var frame_step_offset_y = 0;
var original_frame_step_offset_x = 0; var original_frame_step_offset_y = 0;
Expand Down Expand Up @@ -671,6 +674,7 @@ chrome.download = function(url,filename) { // download function for downloading
casper.echo('ERROR - for headless and visible Chrome, download file using normal webpage interaction');}; */

chrome.download = function(location) { // download function for setting location of downloaded files
download_path = location; // to store the default download location for subsequent URL visits
// below replacement line to set path correctly on Windows to be sent to Chrome browser method
if (location.indexOf(':')>0) location = location.replace(/\//g,'\\\\').replace(/\\\\/g,'\\\\');
chrome_step('Page.setDownloadBehavior',{behavior: 'allow', downloadPath: location});}
Expand Down
4 changes: 2 additions & 2 deletions src/tagui_parse.php
Original file line number Diff line number Diff line change
Expand Up @@ -693,8 +693,8 @@ function call_py($input_intent) { // helper function to use Python integration f

// set of functions to interpret steps into corresponding casperjs code
function url_intent($raw_intent) {if (substr(strtolower($raw_intent),0,4)=="www.") $raw_intent = "https://" . $raw_intent;
$twb = $GLOBALS['tagui_web_browser']; $casper_url = $raw_intent; $chrome_call = '';
if ($twb == 'chrome') {$chrome_call = "var download_path = flow_path; // to set path correctly for Windows\n" .
$twb = $GLOBALS['tagui_web_browser']; $casper_url = $raw_intent; $chrome_call = ''; if ($twb == 'chrome')
{$chrome_call = "if (download_path == '') download_path = flow_path; // below to set path correctly for Windows\n" .
"if (download_path.indexOf(':')>0) download_path = download_path.replace(/\//g,'\\\\').replace(/\\\\/g,'\\\\');\n" .
"chrome_step('Page.setDownloadBehavior',{behavior: 'allow', downloadPath: download_path});\n";
$casper_url = 'about:blank'; $chrome_call .= "chrome_step('Page.navigate',{url: '".$raw_intent."'}); sleep(1000);\n";}
Expand Down

0 comments on commit 04ef454

Please sign in to comment.