My code:
let w1 = new BrowserWindow();
let w2 = new BrowserWindow();
w1.webContents.session == w2.webContents.session
The result is true.
It's my wrong ? Is The web content's session a default session? If so,How can i get the different session in different browser web content?
I try to config:
let w1 = new BrowserWindow({
webPreferences : { session: newSession }
})
when new a BrowserWindow object. But newSession.setProxy() or w1.webContents.session.setProxy() will be dose not work.
Related
I have an Angular application that downloads a file to open in a new tab. It works perfectly on any plateform except on IOS where nothing happens. I make the call in the subscribe because during the download I display a spinner before opening the document on a new tab
this.myservice.dowloadFile(id).subscribe((res) =>
{
let blob = new Blob([file], {type: "application/pdf"});
const url = window.URL.createObjectURL(blob);
let anchor = document.createElement("a");
anchor.href = url;
anchor.target = '_blank';
anchor.click();
this.loadData = false;
});
}
I don't understand the problem.
Is it possible to open headless browser in puppeteer electron?
I am opening the window like this:
const browser = await pie.connect(app, puppeteer);
const page = await pie.getPage(browser, win);
import { app, BrowserWindow } from 'electron'
const pie = require('puppeteer-in-electron')
const puppeteer = require('puppeteer-core')
const browser = await pie.connect(app, puppeteer)
const window = new BrowserWindow({ show: false })
page = await pie.getPage(browser, window)
// ...the rest of the code
Seems it's the only way other than modifying puppeteer-in-electron code
I wrote this code as a Cloudflare Service Worker which is meant to precisely emulate their native function for "Bypass cache on cookie". Specifically, if someone has a Wordpress cookie - it would bypass cache, otherwise it does not.
It does not seem to function at all - in that despite having a cookie and being logged in (confirmed via Chrome developer tools) - I still get a Cloudflare cache HIT on this example domain - Tallyfy. Anything wrong with it? Help appreciated!
// A Service Worker which skips cache if the request contains a cookie.
addEventListener('fetch', event => {
let request = event.request;
var flag=false;
if(request.headers.cookie) {
var pairs = request.headers.cookie.split(";");
var patt = new RegExp("wp-.*|wordpress.*|comment_.*|woocommerce_.*")
for(var i=0;i<pairs.length;i++){
if(patt.test(pairs[i])){
flag = true;
break;
}
}
}
if (request.headers.has('Cookie') && flag) {
// Cookie present. Add Cache-Control: no-cache.
let newHeaders = new Headers(request.headers)
newHeaders.set('Cache-Control', 'no-cache')
event.respondWith(fetch(request, {headers: newHeaders}))
}
// Use default behavior.
return
})
try this and let me know
addEventListener('fetch', event => {
let request = event.request
var flag = false;
if (request.headers.has('Cookie')) {
var cookie = request.headers.get('Cookie');
pairs = cookie.split(";");
var patt = new RegExp("wordpress_logged_in.*|wp_woocommerce_session.*");
for(var i=0;i<pairs.length;i++){
if(patt.test(pairs[i])){
flag = true;
break;
}
}
console.log(flag);
if (request.headers.has('Cookie') && flag) {
let newHeaders = new Headers(request.headers)
newHeaders.set('Cache-Control', 'no-cache')
newHeaders.set('Pragma', 'no-cache')
event.respondWith(fetch(request, {headers: newHeaders}))
}
// Use default behavior.
return;
}
})
I need to create automaion client for Azure webhook.
Following code is written by me to get AutomationManagementClient Value.
var cert = new X509Certificate2(Convert.FromBase64String(ConfigurationManager.AppSettings["CertBase64String"]));
var creds[![enter image description here][1]][1] = new CertificateCloudCredentials(ConfigurationManager.AppSettings["SubscriptionId"], cert);
AutomationManagementClient automationManagementClient = new AutomationManagementClient(creds);
I need that certificate string i.e. CertBase64String value as I don't know from where I will get that value.
Help me...
This error I am getting after updating as per your answer.
If you want to create the automation client, I suggest you try to use the ARM way to operate the automation. The following is the demo code works correctly on my side.
Prepare: Registry an AD application and assign role to applcation, more details please refer to Azure official tutorials. After that we can get tenantId, appId, secretKey from the Azure Portal.
We could use the following code to get the token
var tenantId = "tenantId";
var context = new AuthenticationContext($"https://login.windows.net/{tenantId}");
var clientId = "application Id";
var clientSecret = "client secret";
var resourceGroup = "resource group";
var automationAccount = "automationAccount";
var subscriptionId = "susbscriptionId";
var token = context.AcquireTokenAsync(
"https://management.azure.com/",
new ClientCredential(clientId, clientSecret)).Result.AccessToken;
if you use the Microsoft.Azure.Management.Automation Version <= 2.0.4 please try the following code.
var automationClient = new AutomationManagementClient(new TokenCloudCredentials(subscriptionId,token));
var webhook = automationClient.Webhooks.CreateOrUpdate(resourceGroup, automationAccount,new WebhookCreateOrUpdateParameters
{
Properties = new WebhookCreateOrUpdateProperties
{
ExpiryTime = DateTimeOffset.Now.AddDays(1),
IsEnabled = false,
Parameters = parameters,
Runbook = new RunbookAssociationProperty
{
Name = "xxxx"
},
Name = "xxxx",
Uri = "https://xxxx.xx"
}
});
if use the Microsoft.Azure.Management.Automation Version 3.0.0-preview, please try to the following case.
var automationClient = new AutomationClient(new TokenCredentials(token)) {SubscriptionId = subscriptionId};
var webhook = automationClient.Webhook.CreateOrUpdate(resourceGroup, automationAccount, "webhookName",
new WebhookCreateOrUpdateParameters
{
ExpiryTime = DateTime.Now.AddDays(1),
IsEnabled = false,
Parameters = parameters,
Name = "xxxxx",
Runbook = new RunbookAssociationProperty
{
Name = "xxxxx"
},
Uri = "https://xxx.xxx"
});
Update:
You could set the Parameters = null or if you have parameter, you could define the parameters as dictionary. Please also add the Name = "xxxx" in the code.
var parameters = new Dictionary<string, string> {{"test", "test"}};
var webhook = automationClient.Webhooks.CreateOrUpdate(resourceGroup, automationAccount,new WebhookCreateOrUpdateParameters
{
Properties = new WebhookCreateOrUpdateProperties
{
ExpiryTime = DateTimeOffset.Now.AddDays(1),
IsEnabled = false,
Parameters = parameters,
Runbook = new RunbookAssociationProperty
{
Name = "xxxx"
},
Name = "xxxx",
Uri = "https://xxxx.xx"
}
});
I test it on my side, it works correctly
"CertBase64String" will get by passing thumb-print of that certificate to following fucntion.
internal static X509Certificate2 GetCertificateFromthumbPrint(String certThumbPrint) {
X509Store certStore = new X509Store(StoreName.My, StoreLocation.CurrentUser);
certStore.Open(OpenFlags.ReadOnly);
//Find the certificate that matches the thumbprint.
X509Certificate2Collection certCollection = certStore.Certificates.Find(X509FindType.FindByThumbprint, certThumbPrint, false);
certStore.Close();
//Get the first cert with the thumbprint
X509Certificate2 cert = (certCollection.Count > 0) ? certCollection[0] : null;
return cert;
}
I need to query VSTS work items using Wiql from vsp-node-api package, Please provide any examples if possible.
Refer to following code for details:
import * as vm from 'vso-node-api/WebApi';
import * as wa from 'vso-node-api/WorkItemTrackingApi';
import * as wi from 'vso-node-api/interfaces/WorkItemTrackingInterfaces';
import * as vss from 'vso-node-api/interfaces/Common/VSSInterfaces';
import * as core from 'vso-node-api/interfaces/CoreInterfaces';
var collectionUrl = "https://xxxxxx.visualstudio.com";
let token: string = "PersonalAccessToekn";
let creds = vm.getPersonalAccessTokenHandler(token);
var connection = new vm.WebApi(collectionUrl, creds);
let vstsWI: wa.IWorkItemTrackingApi = connection.getWorkItemTrackingApi();
async function WIQLquery() {
let teamC: core.TeamContext = {project: "", projectId: "", team: "", teamId: "" };
let wiqls: wi.Wiql = { query: "Select [System.Id] From WorkItems Where [System.WorkItemType] = 'Task' And [System.TeamProject] = 'Project'"};
let queryResult: wi.WorkItemQueryResult = await vstsWI.queryByWiql(wiqls, teamC);
queryResult.workItems.forEach(s=>console.log(s.url));
}
WIQLquery();
Here is how I did it, using Javascript instead of Typescript.
Shout out to Eddie Chen for leading me in the right direction.
// file - models/witModel.js
var azdev = require("azure-devops-node-api");
var Model = function(){};
Model.prototype.getWiqlQuery = function(wiqlQuery, teamName){
return new Promise(function(resolve, reject){
const orgUrl = process.env.ADOURI; // ex. https://dev.azure.com/<your org>
const token = process.env.ADOPAT; // Your personal access token
const teamProject = process.env.ADOPROJ;// Team Project
let authHandler = azdev.getPersonalAccessTokenHandler(token);
let connection = new azdev.WebApi(orgUrl, authHandler);
connection.getWorkItemTrackingApi().then(function(witAPI){
var teamContext = {project: teamProject, team: teamName };
witAPI.queryByWiql(wiqlQuery, teamContext).then(function(queryResult){
resolve(queryResult);
}).catch(function(err){reject(err)});
}).catch(function(err){
reject(err);
});
});
};
module.exports = new Model();
And this was how I used it.
// usage - the above code was saved in a module called witModel.js
// feel free to put the module where you need to.
var witModel = require("./models/witModel.js");
// form query and set the value of the teame to query
var query = {query: "your wiql query"};
var team = "team name in Azure DEvops";
// call the promise and handle resolve/reject - then/catch
witModel.getWiqlQueryResuults(query,team).then(function(data){
console.log(data);
}).catch(function(err){
console.log(err)
});