Delay the opening of other tabs, until the first tab loads completely - google-chrome-extension

I am creating a Chrome Extension, using JS that takes a user prompted URL parses some variables out of it, and then loads multiple tabs based on the information that was parsed. The issue, is that before I can do that, I need to wait for a login tab to complete loading, before trying to open the other tabs. So the preferred order would be
User Prompt
Load Login Tab
Wait until Login Tab is loaded
Open remaining tabs.
My code is as below
var URL_Proper = prompt ('Paste the Become-User-ID URL below:');
var User_ID = URL_Proper.substring(URL_Proper.indexOf('?become_user_id=')+16,URL_Proper.length);
var Domain = 'https://' + URL_Proper.substring(8,URL_Proper.substring(8,URL_Proper.length).indexOf('/')+8);
var win = window.open(Domain + 'login_key', '_blank');
var win = window.open(URL_Proper, '_blank');
var win = window.open(URL_Proper.substring(0,URL_Proper.indexOf('?')), '_blank');
var win = window.open(Domain.substring(0)+'/users/'+User_ID, '_blank');
The delay I would like would be between the (Domain + 'login_key', '_blank'); and the other three tabs, but I can't for the life of me figure it out. My guess is this would be better served with chrome.tabs.create, but I am such a beginner that I can't figure out how to do that, nor can I figure out how to make the code wait for the first tab to load, before opening all the other tabs.
Thank you.

Related

How to fix "Not allowed to load local resource" Node-JS

I am making an Electron app that when a button is clicked it creates a new window and loads HTML into it, but for some reason the HTML isn't loaded into it and when I toggle developer tools for the window it shows me in the console this error:
"Not allowed to load local resource". It doesn't tell me a specific line.
const electron = require('electron');
const {ipcRenderer} = electron;
const {BrowserWindow} = electron.remote;
// NewTODO window variable
let newTodoWindow;
// Function to call when "New todo" button is clicked
function NewTodo(){
// Creates a NewTODO window
createTodoWindow();
}
function createTodoWindow(){
newTodoWindow = new BrowserWindow({});
newTodoWindow.loadFile("./newTodoWindow.html");
newTodoWindow.setSize(400 , 400);
}
All it needs to do is that when createTodoWindow function is called(And it is called) it would create a new window and load the HTML to it, but it only creates the window without loading the HTML.
I am not sure why that goes like and I would really appreciate getting help.
So apparently this error occurs when trying to require a file that doesn't exist and that's exactly what I tried doing, For some reason I changed the file I tried requiring and just forgot to require the file with the right name.

Python POST opens a new tab when logging in. How do i get the new tab

Currently using Requests to try to log into https://mypay.dfas.mil/mypay.aspx. My problem is I don't know how to get the page this generates in a new tab upon login.
import requests
url = 'https://mypay.dfas.mil/mypay.aspx'
payload = {'visLogin': 'id', 'visPin': 'pass'}
r = requests.post(url, data=payload)
print(r.text)
This gives me the same page back because it opens a new tab. I just need to get past this part and everything else is generated in the same tab.

How to download file from Server in React.js [duplicate]

I want to perform a javascript xhr request for a png file from a C# webserver which I wrote.
Here is the code I use
var imgUrl = "http://localhost:8085/AnImage.png?" + now;
var request = new XMLHttpRequest();
request.open('GET', imgUrl, false);
request.send(); // this is in a try/catch
On the server-side I send back the file and add a Content-Disposition header.
I obtain the following response
I made sure that Content-Disposition was attached in the headers after the Content-Type (the screenshot is from Firebug, which appends in alphabetical order).
The results is that no dialog box is triggered, am I missing something in the response?
edit:
I want to perform everything in javascript for several reasons.
First: I don't want to show the image and I want to keep everything behind the curtain.
Second: when requesting the image I want the Content-Disposition to be added only on particular requests. Such requests are marked with a "Warning" header with value "AttachmentRequest"
request.setRequestHeader("Warning","AttachmentRequest");
I don't think Content-Disposition triggers any file save dialog when the request is via XHR. The use of XHR suggests you're going to handle the result in code.
If you want the user to be prompted to save the image to a file, I've used this technique successfully:
window.open("http://localhost:8085/AnImage.png?" + now);
It has the downside that it flashes a blank open window briefly until the header arrives, then the new window closes and the "save file" dialog box appears.
Using an iframe may prevent the window flashing:
var f = document.createElement('iframe');
f.style.position = "absolute";
f.style.left = "-10000px";
f.src = "http://localhost:8085/AnImage.png?" + now;
document.body.appendChild(f);
Separately, I wonder what effect (if any) Content-Disposition has on the handling of an img element:
var img = document.createElement('img');
img.style.position = "absolute";
img.style.left = "-10000px";
img.src = "http://localhost:8085/AnImage.png?" + now;
document.body.appendChild(img);
I haven't tried that, but the browser might respect the header. You'd need to be sure to test on all of the browsers you want to support.

Mozilla Addon SDK - Possible to save changes programmatically via simple-prefs?

Is it possible to update a firefox addon's preferences programmatically?
Given the following:
const prefs = require("sdk/simple-prefs");
prefs.stringPreference = "some random string";
It seems that my update to stringPreference doesn't get persisted, and will revert back to the value in about:addons when reloaded, new tabs are opened, etc.
Is this possible? The docs imply changes are saved automatically but this doesn't seem to be the case..
You have missed the .prefs attribute. It should be:
var prefs = require("sdk/simple-prefs").prefs;
Notice the .prefs at the end of the line.

Flex - how to download a string variable as a file to the local machine?

I have a String variable in my flex (flash builder 4) application containing CSV data. I need to allow the user to download this data to a local file. For example, giving them a "csv" button to click and it might present them with a save file dialog (and I would be sending the contents of my string variable).
Is this possible / how ?
I am using the ResuableFX component for the datagrid to csv. This the code I ended up with that works to save the string to a text file for the user (in a web browser):
var dg2CSV:DataGrid2CSV = new DataGrid2CSV();
dg2CSV.includeHeader=true;
dg2CSV.target=adgEncounters;
var csvText:String=dg2CSV.getCSV();
var MyFile:FileReference = new FileReference();
var csvFileNameDT:String = QuickDateFormatter.format(new Date().toString(),"YYYYMMDDJJNNSS");
MyFile.save(csvText,"Encounters"+csvFileNameDT+".csv");
If you're in an AIR App you can use File.browseForSave().
If you're in a web app, you can use FileReference.save() . The FileReference docs have a lot more info on this.
In many cases, I would recommend using navigateToURL() to open the file outside of Flash and let the browser deal with it.
I'm not sure if there is a way to do this without user interaction.

Resources