Can the default behavior of Bluetooth mouse right click as “Go Back” in Android Chrome be disabled by Javascript?
I tried event.preventDefault() without success
Blancer.com Tutorials and projects
Freelance Projects, Design and Programming Tutorials
Category Added in a WPeMatico Campaign
Can the default behavior of Bluetooth mouse right click as “Go Back” in Android Chrome be disabled by Javascript?
I tried event.preventDefault() without success
I am trying to upload an image to Cloudinary from an Ionic IOS app. I am sending the file using FormData but CapacitorHttp is enabled in the app in order to deal with CORS issues. However, FormData does not work with CapacitorHttp.
I have tried using fetch API, as well as Axios and also Angular HttpClient, but all http requests go through CapacitorHttp.
So I would like to know if there is a way to make this post request containing FormData that bypasses the CapacitorHttp just for this one request, or if there is another way I can go about this.
I am solving a ‘hackerRank’ coding challenge (basic) using JavaScript. the problem is,
You will be given a list of 32 bit unsigned integers. Flip all the bits (1->0 and 0->1) and return the result as an unsigned integer.
here is my code (I aware that i tried a cumbersome way and there is a very easy single line to code as well return (~n >>> 0)
function flippingBits(n) {
function dtb(num){
let rem = 0 ;
let i = 0;
let op = 0;
while(num !== 0){
rem = num % 2;
op = op + (rem*(Math.pow(10,i)));
i++;
num = Math.floor(num/2);
}
return String(op).padStart(32,'0');
}
function toggle(n){
let newOp = dtb(n);
let finalOp = '';
for(let i=0;i<newOp.length;i++){
if(newOp[i] === '1'){
finalOp += '0';
} else {
finalOp += '1';
}
}
return finalOp;
}
function btd(n){
let num = toggle(n);
let op = 0;
for(let i=0;i<num.length;i++){
op = op + (Math.pow(2,(num.length- 1)-i)*num[i]);
}
return op;
}
return btd(n);
}
the inputs that passed
enter image description here
the inputs that failed
Input (stdin)
3
0
802743475
35601423
my Output (stdout)
4294967295
4292350879
4293886735
Expected Output
4294967295
3492223820
4259365872
Nightwatch with Cucumber. I want to check if the elements listed in an Excel sheet are present on the webpage. To do this, a sequential promise(using reduce) is written to ensure that the page loads and each element is verified.
When test is ran, the element verification works fine using waitForElementVisible if the element is present . However, when an element is not present, “Error: function timed out, ensure the promise resolves within 50000 milliseconds” issue is encountered.
I tried increasing the implicit wait time using client.waitForElementVisible(record[“Locator”],60000);
, but it also fails. Now, I get both the “Error: function timed out, ensure the promise resolves within 50000 milliseconds” and a “Timed out while waiting for element to be present for 60000 milliseconds”
const sheetData = file[sheetName];
return sheetData
.reduce((promiseChain, record, index) => {
return promiseChain.then(() => {
return page.load(param)// Adjust timeout as needed
.then(() => {
return page.waitForPageLoad();
})
.then(async() => {
await client.waitForElementVisible(record["Locator"],60000); //FAILS AT THIS STEP
})
.then(() => {
results.push({ "status": "fulfilled", index: index + 1 });
})
.catch((error) => {
results.push({ "status": "rejected", index: index + 1, error});
return Promise.resolve();
});
});
}, Promise.resolve())
.then(() => {
const failures = results.filter((result) => result.status === "rejected");
if (failures.length > 0) return Promise.reject(failures);
return Promise.resolve(true);
}).catch((finalError) => {
console.error("Final errors encountered: ", finalError);
});
When additional timeout is provided as in
client.waitForElementVisible(record["Locator"],60000);
Error: function timed out, ensure the promise resolves within 50000 milliseconds
at Timeout.<anonymous> (C:[email protected]:54:20)
at listOnTimeout (node:internal/timers:573:17)
at process.processTimers (node:internal/timers:514:7)
Timed out while waiting for element to be present for 60000 milliseconds. - expected "visible" but got: "not found"
When no timeout/<60000 millisec timeout is provided:
client.waitForElementVisible(record["Locator"]); OR
client.waitForElementVisible(record["Locator"],10000);
Error: function timed out, ensure the promise resolves within 50000 milliseconds
at Timeout.<anonymous> (C:[email protected]:54:20)
at listOnTimeout (node:internal/timers:573:17)
at process.processTimers (node:internal/timers:514:7)
and chrome process still runs(browser not closed)
chrome browser tests exited with code: 1
error: .api.url() returned a value that is not a string, probable cause is an alert popup! {"timestamp":"2024-08-09T03:10:19.369Z"}
error: null {"timestamp":"2024-08-09T03:10:19.372Z"}
error: .api.url() returned a value that is not a string, probable cause is an alert popup! {"timestamp":"2024-08-09T03:10:19.906Z"}
error: null {"timestamp":"2024-08-09T03:10:19.907Z"}
error: .api.url() returned a value that is not a string, probable cause is an alert popup! {"timestamp":"2024-08-09T03:10:20.448Z"}
error: null {"timestamp":"2024-08-09T03:10:20.448Z"}
Also tried using Promise.race by creating a customTimeout(40000, 70000) as below
return page.load(param)
.then(() => {
return page.waitForPageLoad();
})
.then(() => {
const timeoutPromise = new Promise((_, reject) =>
setTimeout(() => reject(new Error(`Timeout waiting for element: ${record["Locator"]}`)), 40000)
);
const elementPromise = new Promise((resolve, reject) => {
client.element('css selector', record["Locator"], function(result) {
if (result.status != -1) {
resolve(result);
} else {
reject(new Error(`Element not found: ${record["Locator"]}`));
}
});
});
return Promise.race([elementPromise, timeoutPromise]);
})
both resulted in
Error: function timed out, ensure the promise resolves within 50000 milliseconds
at Timeout.<anonymous> (C:[email protected]:54:20)
at listOnTimeout (node:internal/timers:573:17)
at process.processTimers (node:internal/timers:514:7)
As the list of elements/pages to verify are dynamically changes(adobe analytics), I cannot give timeout at step level(as suggested in few answers), as this depends on the excel records and any step level time out may stop reading records.
Can you please suggest how to bypass the “function timeout” error and instead only track the elements that are not available, continuing to check for the remaining elements even if one is not found?
I’m using JS to add a CSS class to an HTML element in conjunction with Elementor but it’s not working. The code is inserted in the footer of the page using script tags.
Here is the code:
<script type="text/javascript">
/*position fixed-menu on scroll*/
if( $('.site-header').hasClass('header-layout3') ){
var hdrOuter = '.site-header.header-layout3';
var fixHandle = '.site-header .site-main-nav-wrapper';
}else{
var hdrOuter = '.site-header .lite-nav-wrapper';
var fixHandle = '.site-header .lite-nav-wrapper';
}
//sticky menuy for mobile device
if ($(window).width() <= 768){
var hdrOuter = '.lite-mob-outer';
var fixHandle = '.lite-mob-outer';
}
var getHeaderHeight = $(hdrOuter).outerHeight();
var lastScrollPosition = 0;
$(window).scroll(function() {
var currentScrollPosition = $(window).scrollTop();
if ($(window).scrollTop() > 2.3 * (getHeaderHeight) ) {
$(fixHandle).addClass('menu-fixed-triggered');
if (currentScrollPosition > lastScrollPosition) {
$(fixHandle).removeClass('menu-fixed');
}else{
$(fixHandle).addClass('menu-fixed');
}
lastScrollPosition = currentScrollPosition;
} else {
$(fixHandle).removeClass('menu-fixed');
$(fixHandle).removeClass('menu-fixed-triggered');
}
});
</script>
And this is the element it should be adding a class to:
<header class="elementor-element elementor-element-c4e8bd8 e-con-full site-header elementor-hidden-tablet elementor-hidden-mobile e-flex e-con e-parent e-lazyloaded" data-id="c4e8bd8" data-element_type="container" id="masthead" data-settings="{"background_background":"classic"}">
<div class="elementor-element elementor-element-928b162 e-con-full lite-nav-wrapper e-flex e-con e-child" data-id="928b162" data-element_type="container" data-settings="{"background_background":"classic"}">
</div>
</header>
I am trying to create this HOC–>
export const hocGrid = (Grid) => {
return ({ data, config, id = uuidv4(), adaptableReady, autosizeAllColumns, removeLoader }) => {
return (
<Grid data={data} config={config} id={id} adaptableReady={adaptableReady} autosizeAllColumns={autosizeAllColumns} removeLoader={removeLoader} />
)
}
}
this Grid component receives data and config as props, data is array of object and config is object
I want to modify these data and config and then pass to Grid. Is this possible through HOC?
In my project, I want to implement a feature that calls up to n APIs (where n ≤ 4) to fetch images and then displays them in a list. I use a state called listImages to manage this.
Here’s how it should work:
I tried using Promise.all or Promise.allSettled, but it seems they don’t meet my requirements. I want to find a way to call APIs asynchronously but handle the results in the same array, maintaining the order of the requests. How can I do that?
Thank you so much!
I have configured a three.js project with an index.html file in directory C:Usersharryworkspacetest where the last commands in PowerShell are:
npm install --save three
npm install --save-dev vite
I have configured vite.config.mjs in the same directory with the following javascript content so that when I run npx vite it will automatically open my index.html file in a browser. This works perfectly fine.
import { defineConfig } from 'vite';
export default defineConfig({
server: {
open: true // Automatically open the browser
}
});
I’m currently running the following Python script within Blender 4.2 using its integrated Text Editor. However, it should also work independently by using a standard Python interpreter.
import subprocess
import os
directory = r'C:Usersharryworkspacetest'
command = 'npx vite'
subprocess.run(command, shell=True, cwd=directory, check=True)
This one works perfectly fine and displays the following output in the console and also successfully opens a browser tab with my index.html content:
Is it possible to configure vite to automatically stop the server when the browser tab is closed? I’m looking for a way to have the server detect when no clients are connected and shut down automatically. Currently, I have to manually stop the server by pressing qEnter in the console, because this server process blocks the Blender UI. Ideally, I’d like to run the script to test some output in the browser, then continue editing in Blender, and easily test again. Is this possible? Maybe by some additional config inside of vite.config.mjs?
I have a ReactJS project in an advance stage and I want to migrate it to ReactTS (Typescript).
How can I accomplish that?
I try adding a ts-config file and when I use tsx file they are not recognize and I don’t know what I’m missing.
I’m working on creating a custom component for React-Select that adds a button to the options.
const customSingleValue = ({ data }) => (
<div className="custom-single-value">
<span> {data.label} </span>
<button>Click me</button>
</div>
);
<Select
className="dropdown"
options={fruitOptions}
components={{ SingleValue: customSingleValue }}
/>
However, I’m having trouble integrating this with React-Select’s input/search feature. The button appears on a separate line, but I want it to stay on the same line as the input/search. Additionally, I want the base functionality of the custom component to be overwritten/hidden by the input/search when the user starts typing.
Question: How can I ensure my custom component stays on the same line as the input/search and is replaced by the input/search when the user starts typing, same as the default behavior?
Full Code:
import Select from "react-select";
const DropdownTest = () => {
const fruitOptions = [
{ value: 'apple', label: 'Apple' },
{ value: 'banana', label: 'Banana' },
{ value: 'cherry', label: 'Cherry' },
{ value: 'date', label: 'Date' },
{ value: 'fig', label: 'Fig' }
];
const customSingleValue = ({ data }) => (
<div className="custom-single-value">
<span> {data.label} </span>
<button>Click me</button>
</div>
);
return (
<div className="dropdown-container">
<Select
className="dropdown"
options={fruitOptions}
components={{ SingleValue: customSingleValue }}
/>
</div>
);
};
export default DropdownTest;
How to send child window values to parent window in local PC?
I would likt to just send child window value to parent window or call function from parent window in local PC. (display.html => Control.html)
but, my Web browser chrome, edge also cause CORS error.
I just would likt to make some html files and test in my local PC. How solve this problem?
I tried to configure chrome web browser but it doesn’t work.
[my chrome web browser version: 126.0.6478.127(public build) (64bit)]
here below my code and error capture.
Please let me know, Thanks 🙂
* parent window: Control.html
* child window: display.html
* my chrome browser error capture
Having done this for awhile, I’d love a quick sanity check: in a web app using the History Web API is there any way to replicate state persistence across multiple primary nav tabs like you might expect in a native application? The only reasonable approach I can imagine uses iFrames with separate isolated experiences and manually triggering history events within each. But the browser back button would remain blissfully unaware of anything besides navigation in the parent wrapper between the 4-5 tabs.
I’m making a web app that a user can drag and drop images and videos into.
I’ve figured out how to attach images and mp4 videos, but I can’t seem to attach MOV videos (the main video type I want to handle). I’m not sure if FileReader is incompatible with quicktime videos, but if it is, the other option seems to be the createObjectURL() method, which I’ve read is deprecated.
I would appreciate any suggestions for how to fix this. Thank you in advance.
This is what I’ve tried for handling a file drop. Every time I attempt to drop a MOV video (the type is “video/quicktime”), I see a dark video file icon that never loads into a video.
function handleFileDrop(e) {
e.preventDefault();
let files = e.dataTransfer.files; // holds the file(s) I want to attach
let section = e.target; // the element I want to attach files to
if (files.length) { // if dropping a new file
for (let i = 0; i < files.length; i++) {
let file = files[i];
let fileName = files[i].name;
if (file.type.startsWith('image')) {
attachImage(file, fileName, section);
} else if (file.type.startsWith('video')) {
attachVideo(file, fileName, section);
}
}
} else {
// this code is for swapping around existing files; not relevant
}
}
function attachVideo(file, fileName, section) {
let reader = new FileReader();
reader.onload = function(e) {
let video = document.createElement('video');
video.src = e.target.result;
video.id = fileName;
video.controls = true;
section.appendChild(video);
}
reader.readAsDataURL(file);
}
I am trying develop a script which prints Domestic label for USPS. I contacted USPS they asked me to use https://developer.usps.com/api/71 , but there is not any script in PHP or JavaScript to do it . If anyone knows how to print it show me script I will really appriciate it.
Thank in Advance
I tried it with XML api but it will be phased out soon so I need to utilize new api
I have two hidden DIVs on my page with buttons to toggle them when needed. One is the navigation menu and the other is a log-in form. I’ve used JQuery to toggle a nice slide down and up. I’ve now added some JavaScript to toggle the slide out when a user clicks on their respective buttons a second time or if they click outside of the revealed DIV.
Problem is, my JavaScript toggles both DIVs to appear and disappear together, regardless of which button you press!
$('html').click(function (e) {
if (e.target.id == '#nav_btn') {
$("#navigation").slideToggle("slow");
} else {
$("#navigation").slideToggle("slow");
}
});
$('html').click(function (e) {
if (e.target.id == '#log_btn') {
$("#loginDIV").slideToggle("slow");
} else {
$("#loginDIV").slideToggle("slow");
}
});
It’s no doubt something really obvious but what am I doing wrong?!