I want to detect if my extension has been installed from a normal browser or with an automation tool. in Manifest v2 it was possible because we could access the window object from the background and we use navigator.webdriver property but now in Manifest v3 we can't anymore because of Service Worker.
Is there any alternative solution?
Update:
Here I got the solution in other way. Like we can detect if extension crx file is loaded locally from below method-
const self = await browserType.management.getSelf();
if(self.installType === "normal"){
console.log("extension installed locally");
}
else if(self.installType === "development"){
console.log("extension installed from store"); }
Method one
let id = chrome.runtime.id
if (id)
console.log("id found, not headless")
Method Two
let checkIfheadless = navigator.language || navigator.userLanguage || navigator.browserLanguage || navigator.systemLanguage if (checkIfheadless) console.log("not headless")
Method Three
const phantomJsCheck = function () {
if (!Function.prototype.bind) {
console.log("PhantomJS environment detected. #1");
return;
}
if (Function.prototype.bind.toString().replace(/bind/g, 'Error') != Error.toString()) {
console.log("PhantomJS environment detected. #2");
return;
}
if (Function.prototype.toString.toString().replace(/toString/g, 'Error') != Error.toString()) {
console.log("PhantomJS environment detected. #3");
return;
}
console.log("PhantomJS environment not detected.");
}
Related
I am implementing fingerprint scanning in my RN app and I found a good tutorial for that but the code there has a syntax which I have never used - yield call(), however, I googled it and couldn't find a proper explanation for it.
Here is the code:
if (isFingerPrintSupported === true) {
yield call(KeychainService.setCredentials, user_name,
JSON.stringify({ password }));
}
Is there something else I can use instead in this case? if not then how can I import this or install in order to make it work?
EDIT(example code added):
componentWillMount() {
let credentials = yield call(KeychainService.getCredentials);
if (credentials && credentials.username)) {
let isFingerPrintSupported = yield call(KeychainService.checkBiometricSupportednEnrolled);
if (isFingerPrintSupported === true) {
// show fingerprint alert on login page
// and authenticate FingerPrint when user touch the sensor
}
} else {
// else don’t show fingerprint option on login
}
}
yield can be used inside a generator function & it helps to pause and resume a function at any time asynchronously. Also Additionally it helps to return value from a generator function.
Check this document for more information.
call is redux-saga effects which help to make asynchronous calls. Check this for more information.
import { call } from 'redux-saga/effects'
function* authorize(user, password) {
try {
const response = yield call(/** Api call */, user, password)
...
} catch(error) {
...
}
}
Note
If you don't want to use yield, you can directly call you API with params using axios or fetch.
Hope this helps you. Feel free for doubts.
I would appreciated some help please even if this is maybe a trivial question.
I've written a SwiftUI app that reads the media library from the device and plays it depending on user settings. That is all fine.
The problem I have is that if you install the app for the first time, the user needs to grant permission to access the media library. This appears to be a system generated dialog but I cannot see which step in the also triggers it. I tried to have the access request be triggered code generated but that doesn't seem to trigger the pop up but it still only appears at a later stage in the app load process. The code seems to recognise though that the user reacted to the access request pop up and does select the correct switch case.
What it does not seem to do though is that it still can't read the media library. The MPMediaQuery returns nil.
My suspicion is that it somehow connected to the fact that the access request doesn't run on the main thread but I am not experienced enough in Swift programming to know what the problem is. I would be most grateful for some helpful hints.
Here is my code:
import MediaPlayer
import SwiftUI
import Foundation
class Library {
var artists : [Artist] = []
#EnvironmentObject var settings : UserSettings
var counter : Float = 0
init() {
switch MPMediaLibrary.authorizationStatus() {
case .authorized:
print("authorized")
case .denied:
print("denied")
return
case .notDetermined:
print("not determined")
MPMediaLibrary.requestAuthorization() { granted in
if granted != .authorized {
return
}
}
case .restricted:
print("restricted")
#unknown default:
print("default")
}
if MPMediaLibrary.authorizationStatus() == .notDetermined { return }
let filter : Set<MPMediaPropertyPredicate> = [MPMediaPropertyPredicate(value: MPMediaType.music.rawValue, forProperty: MPMediaItemPropertyMediaType)]
let mediaQuery = MPMediaQuery(filterPredicates: filter )
var artistsInCollection : [Artist] = []
guard let _ = mediaQuery.items?.count else { return }
for item in mediaQuery.items! {
//here I do something but that's not relevant to my question
}
self.artists = artistsInCollection
}
}
I'm using chrome to debug react native.
When I choose "Pause On Caught Exceptions" under "source" debugging tab, the following exception always occur: TypeError: freeProcess.binding is not a function
The file in which the exception occurs:
http://localhost:8081/< Project_folder >/node_modules/react-proxy/node_modules/lodash/_nodeUtil.js
The exception is in line 18:
return freeProcess && freeProcess.binding('util');
Full code on that .js page:
var freeGlobal = require('./_freeGlobal');
/** Detect free variable `exports`. */
var freeExports = typeof exports == 'object' && exports && !exports.nodeType && exports;
/** Detect free variable `module`. */
var freeModule = freeExports && typeof module == 'object' && module && !module.nodeType && module;
/** Detect the popular CommonJS extension `module.exports`. */
var moduleExports = freeModule && freeModule.exports === freeExports;
/** Detect free variable `process` from Node.js. */
var freeProcess = moduleExports && freeGlobal.process;
/** Used to access faster Node.js helpers. */
var nodeUtil = (function() {
try {
return freeProcess && freeProcess.binding('util');
} catch (e) {}
}());
module.exports = nodeUtil;
What is the most elegant way to avoid this exception?
Thanks!
Ok, so I've solved it temporarily.
I've changed line 18 to:
return freeProcess && (typeof freeProcess.binding === "function") && freeProcess.binding('util');
in this file:
/< Project_folder >/node_modules/react-proxy/node_modules/lodash/_nodeUtil.js
This solution is not the best, because it should be fixed in the git of the library. I think the library is lodash, but I couldn't find the file in its git - https://github.com/lodash/lodash
I am using a feature layer in JSAPI, where I edit a feature by the standard selection, change attributes, applyEdits process. It seems that there is a bug in JSAPI both 3.12 and 3.14 which makes the apply edits fail on certain features. The callback just errors out without any clue.
The interesting observations:
Failure only happens on certain features and all cases belong to a particular layer (other features in that layer are just fine).
Changing from 3.12 to 3.14 the features that cause the error are changed but did not go away.
Here is a quick snippet of the code:
sq = buildSelectionQuery();
if (sq) {
all(assetsFeatureLayers.map(function (l) { return l.selectFeatures(sq, esri.layers.FeatureLayer.SELECTION_NEW).promise;})
).then(function (fls) {
console.log('sel res', fls);
all(fls.map(function (r, i) {
var fs = r[0]; // the first is an array of selected features
var l = assetsFeatureLayers[i];
console.log(fs);
if (fs.length > 0) {
console.log("Switching phases to: ", tph);
fs.forEach(function (f) {
f.attributes['phasecode'] = tph;
});
console.log("Saving switched phases for layer: ", l.name);
return l.applyEdits(null, fs, null); //.promise;
} else {
return null;
}
})).then(function (l) {
console.log("Phase switching finished successfully!", l);
clearAllSelections();
}, function (e) {
console.log("Error switching phases!", e);
clearAllSelections();
});
});
}
OK, I found the root cause. We are using ESRI's PHP proxy, and it was a bug in that. Upgrading to the latest 1.1 beta solved the issue. Here is the link to their repo: https://github.com/Esri/resource-proxy
Is there method to check in Groove availability of object in global scope? My script runs on dev machine and CI. When it runs on CI there is teamcity object but on dev not. Next method throws exception on dev machine.
def isTeamCityAvailable(){
tc = this['teamcity']
if(tc == null){
return false;
}else{
return true;
}
}
If this is in a build.gradle file, you should be able to do:
def isTeamCityAvailable() {
hasProperty( 'teamcity' )
}