JavaScript

RSS for tag

Discuss the JavaScript programing language.

JavaScript Documentation

Posts under JavaScript tag

65 Posts
Sort by:
Post not yet marked as solved
0 Replies
730 Views
Hello, I would reply to this post but the reply button is broken in Chrome and Firefox on Linux..... If I am out of date or have misunderstood then please accept my apologies in advance. I want to do make the following custom element in Safari but it is apparently not currently supported for "ideological" reasons ? class my_special_element extends HTMLInputElement { myCustomFunction(){ self.value="Oh look, I have extended the element class with a new method"; } } //Then in HTML <input is="my-special-element"> I can already, easily extend web components in Safari right now by doing the following - as I have been doing for the past 15 years in all browsers. function my_special_element_pretend_class(element) { self=element; self.myCustomFunction=function(){ self.value="Oh look, I have extended the element class with a new method"; } return self; } //In this case myElement is an "input" element. var myElement = document.getElementById('myElement'); myElement=my_special_element_pretend_class(myElement); myElement.myCustomFunction(); Given that this is so unbelievably easy to do, why is Apple adopting a stance at odds with the W3C over Web Components ? If you're HONESTLY worried about namespace collisions then surely just throw an exception ? Don't we already have to stay on top of bugs caused by new features etc ? Security ? Really ? Please read the code above again ! Surely you'd have to fundamentally alter the core extensibility of Javascript to keep yourself safe from that ? We all breathed a massive sigh of relief when Microsoft killed IE11. Is Safari going to become the hated reason for another zillion bloated, resource consuming polyfills that slow down the UI ONLY on YOUR devices ? Best wishes Chris
Posted
by
Post not yet marked as solved
0 Replies
822 Views
Hello everyone, I've been working on implementing push notifications for the web PWA using JavaScript, and I've encountered an issue specifically with Safari on Mac and iOS devices. While my code snippet works perfectly fine in Chrome, I'm facing a problem with the clients.openWindow function. It doesn't seem to perform any actions or provide any errors. Here's the code snippet for reference: self.addEventListener('push', (event) => { const notification = JSON.parse(event.data.text()); console.log(notification); const title = notification?.notification?.title; const body = notification?.notification?.body; const data = notification?.data; const options = { body, data, icon: '/favicon.ico', badge: '/favicon.ico', vibrate: [100, 50, 100], actions: [ { action: onNotificationAction(notification['data']), title: notification.notification.title, }, ], }; event.waitUntil(self.registration.showNotification(title, options)); }); self.addEventListener('notificationclick', (event) => { console.log(event, 'event'); const notification = event?.notification; event.notification.close(); event.waitUntil( clients .matchAll({ type: 'window', }) .then((clientList) => { for (const client of clientList) { if (client.url === '/' && 'focus' in client) return client.focus(); } if (clients.openWindow) return clients.openWindow('/messages'); }), ); }); After thorough testing, I've determined that the issue lies specifically with the clients.openWindow function. Unfortunately, I haven't been able to identify any errors or determine why it isn't functioning as expected. The goal is to open a new window or focus on an existing one when a notification is clicked. I would greatly appreciate any assistance or insights into resolving this issue. Has anyone else encountered a similar problem with Safari and iOS? Are there any alternative approaches or workarounds that could achieve the desired functionality? Thank you in advance for your help and suggestions!
Posted
by
Post not yet marked as solved
7 Replies
1.6k Views
I am currently facing an issue with PWA (Progressive Web App) push notifications on iOS and would greatly appreciate your assistance in resolving it. The problem I am experiencing is that when attempting to open a specific link from the notificationclick method using clients.openWindow('/messages'), the expected redirection to the "messages" page does not occur. Instead, the PWA opens without navigating to the desired destination. I want to emphasize that this issue is unique to iOS devices. If you have encountered a similar issue or have any suggestions on how to resolve it, please share your thoughts. Thank you in advance for your support and valuable suggestions.
Posted
by
Post not yet marked as solved
2 Replies
990 Views
We have been testing universal links and detected the following: Assuming there is an HTML with embedded JS that redirects to the universal link. **Direct redirection --> WORKS OK ** window.location.href = "https://my-universal-link?data=abc"; Redirection with timeOut or Interval --> NOT WORKING (go to default WEB) setTimeout(function () { window.location.href = "https://my-universal-link?data=abc"; }, 2000); setInterval(function () { window.location.href = "https://my-universal-link?data=abc"; }, 2000);
Posted
by
Post not yet marked as solved
0 Replies
777 Views
I am having a video chat application using react js in the frontend and i have one SFU server which is based on Node js with WRTC library for supporting webRTC apis in the server side(M87). App.js import React, { useState, useRef, useEffect, useCallback } from "react"; import io from "socket.io-client"; import Video from "./Components/Video"; import { WebRTCUser } from "./types"; const pc_config = { iceServers: [ // { // urls: 'stun:[STUN_IP]:[PORT]', // 'credentials': '[YOR CREDENTIALS]', // 'username': '[USERNAME]' // }, { urls: "stun:stun.l.google.com:19302", }, ], }; const SOCKET_SERVER_URL = "https://192.168.132.29:8080"; const App = () => { const socketRef = useRef<SocketIOClient.Socket>(); ...... .......... const createReceiverPeerConnection = useCallback((socketID: string) => { try { const pc = new RTCPeerConnection(pc_config); // add pc to peerConnections object receivePCsRef.current = { ...receivePCsRef.current, [socketID]: pc }; pc.onicecandidate = (e) => { if (!(e.candidate && socketRef.current)) return; console.log("receiver PC onicecandidate"); socketRef.current.emit("receiverCandidate", { candidate: e.candidate, receiverSocketID: socketRef.current.id, senderSocketID: socketID, }); }; pc.oniceconnectionstatechange = (e) => { console.log(e); }; pc.ontrack = (e) => { console.log("ontrack success"); setUsers((oldUsers) => oldUsers .filter((user) => user.id !== socketID) .concat({ id: socketID, stream: e.streams[0], }) ); }; // return pc return pc; } catch (e) { console.error(e); return undefined; } }, []); ...... ............ return ( <div> <video style={{ width: 240, height: 240, margin: 5, backgroundColor: "black", }} muted ref={localVideoRef} autoPlay /> {users.map((user, index) => ( <Video key={index} stream={user.stream} /> ))} </div> ); }; export default App; server.js let http = require("http"); let express = require("express"); let cors = require("cors"); let socketio = require("socket.io"); let wrtc = require("wrtc"); const fs = require("fs"); let https = require("https"); const port=8080; const options = { key: fs.readFileSync("../cert/cert.priv.key"), cert: fs.readFileSync("../cert/cert.chain.pem"), }; const app = express(); const server = https.createServer(options, app); app.use(cors()); let receiverPCs = {}; let senderPCs = {}; let users = {}; let socketToRoom = {}; const pc_config = { iceServers: [ // { // urls: 'stun:[STUN_IP]:[PORT]', // 'credentials': '[YOR CREDENTIALS]', // 'username': '[USERNAME]' // }, { urls: "stun:stun.l.google.com:19302", }, ], }; const isIncluded = (array, id) => array.some((item) => item.id === id); const createReceiverPeerConnection = (socketID, socket, roomID) => { const pc = new wrtc.RTCPeerConnection(pc_config); if (receiverPCs[socketID]) receiverPCs[socketID] = pc; else receiverPCs = { ...receiverPCs, [socketID]: pc }; pc.onicecandidate = (e) => { //console.log(`socketID: ${socketID}'s receiverPeerConnection icecandidate`); socket.to(socketID).emit("getSenderCandidate", { candidate: e.candidate, }); }; pc.oniceconnectionstatechange = (e) => { //console.log(e); }; pc.ontrack = (e) => { if (users[roomID]) { if (!isIncluded(users[roomID], socketID)) { users[roomID].push({ id: socketID, stream: e.streams[0], }); } else return; } else { users[roomID] = [ { id: socketID, stream: e.streams[0], }, ]; } socket.broadcast.to(roomID).emit("userEnter", { id: socketID }); }; return pc; }; const createSenderPeerConnection = ( receiverSocketID, senderSocketID, socket, roomID ) => { const pc = new wrtc.RTCPeerConnection(pc_config); if (senderPCs[senderSocketID]) { senderPCs[senderSocketID].filter((user) => user.id !== receiverSocketID); senderPCs[senderSocketID].push({ id: receiverSocketID, pc }); } else senderPCs = { ...senderPCs, [senderSocketID]: [{ id: receiverSocketID, pc }], }; pc.onicecandidate = (e) => { //console.log(`socketID: ${receiverSocketID}'s senderPeerConnection icecandidate`); socket.to(receiverSocketID).emit("getReceiverCandidate", { id: senderSocketID, candidate: e.candidate, }); }; pc.oniceconnectionstatechange = (e) => { //console.log(e); }; ... ...... const closeReceiverPC = (socketID) => { if (!receiverPCs[socketID]) return; receiverPCs[socketID].close(); delete receiverPCs[socketID]; }; const closeSenderPCs = (socketID) => { if (!senderPCs[socketID]) return; senderPCs[socketID].forEach((senderPC) => { senderPC.pc.close(); const eachSenderPC = senderPCs[senderPC.id].filter( (sPC) => sPC.id === socketID )[0]; if (!eachSenderPC) return; eachSenderPC.pc.close(); senderPCs[senderPC.id] = senderPCs[senderPC.id].filter( (sPC) => sPC.id !== socketID ); }); delete senderPCs[socketID]; }; const io = socketio.listen(server); io.sockets.on("connection", (socket) => { socket.on("joinRoom", (data) => { try { let allUsers = getOtherUsersInRoom(data.id, data.roomID); io.to(data.id).emit("allUsers", { users: allUsers }); } catch (error) { console.log(error); } }); socket.on("senderOffer", async (data) => { try { socketToRoom[data.senderSocketID] = data.roomID; let pc = createReceiverPeerConnection( data.senderSocketID, socket, data.roomID ); await pc.setRemoteDescription(data.sdp); let sdp = await pc.createAnswer({ offerToReceiveAudio: true, offerToReceiveVideo: true, }); await pc.setLocalDescription(sdp); socket.join(data.roomID); io.to(data.senderSocketID).emit("getSenderAnswer", { sdp }); } catch (error) { console.log(error); } }); socket.on("senderCandidate", async (data) => { try { let pc = receiverPCs[data.senderSocketID]; await pc.addIceCandidate(new wrtc.RTCIceCandidate(data.candidate)); } catch (error) { console.log(error); } }); ..... ......... startServer(port); function startServer(port) { server.listen(port, () => { console.log(`[INFO] Server app listening on port ${port}`); }); }
Posted
by
Post not yet marked as solved
0 Replies
512 Views
I'm trying to read the clipboard data using the navigator.clipboard.readText() in the button click handler: <body> <h1>How to paste text</h1> <p><button type=button>Paste</button></p><textarea></textarea> <script> const pasteButton = document.querySelector("button"); pasteButton.addEventListener("click", (async () => { try { const e = await navigator.clipboard.readText(); document.querySelector("textarea").value += e; console.log("Text pasted.") } catch (e) { console.log("Failed to read clipboard. Using execCommand instead."); document.querySelector("textarea").focus(); const t = document.execCommand("paste"); console.log("document.execCommand result: ", t) } })); </script> </body> We can use the following link to check the demo page using the above code: https://web.dev/patterns/clipboard/paste-text/demo.html The demo page works fine when clicking the Paste button on the Chrome browser. But, it shows the Paste menu when clicking the Paste button on the Safari browser. Only when clicking the Paste menu on the Safari browser, the clipboard data is pasted into the text box. So, I'd like to know how to hide the "Paste" menu on Safari browser when using navigator.clipboard.readText() in the button click handler. Thanks.
Posted
by
Post not yet marked as solved
0 Replies
421 Views
We have a website running on Angular/CLI version 11.0.5. On iOS devices running iOS 17, we are encountering an issue where, after logging into our website, the screen becomes unresponsive, and no actions can be performed. The only functionality that remains is scrolling. This issue is specific to iOS 17; everything was working smoothly on iOS 16.6. In the browser console, we are seeing the following errors: ERROR: TypeError: e.reduceRight is not a function. (In 'e.reduceRight((e,t)=&gt;new P(e,t),this.backend)', 'e.reduceRight' is undefined) It's worth noting that this errors were also present in iOS 16.6, but the website was functioning correctly on those devices. However, in iOS 17, after a page refresh, the user can log in, but all subsequent pages become unresponsive. Before logging in, functions like signup and password reset work as expected. We are unsure about the changes made in iOS 17 that could be causing this issue.
Posted
by
Post not yet marked as solved
0 Replies
365 Views
I am trying to locate information or documentation on how to pull in photos from the iCloud Shared Albums, but have not been able to find anything yet. Dakboard is currently doing it so I know it is possible, but I cannot find an API or any documentation covering how to access the photos in a Shared Album for incorporation into web applications. Can anyone help?
Posted
by
Post not yet marked as solved
0 Replies
565 Views
In My PWA app I am using camera of getUserMedia() and html audio tags, So In my app I am using videos audios and camera based on requirements, so When I have updated iOS17 I have stared facing below issue. When I am loading camera after premission given. my audios are playing in ear speaker and not in media speaker only for ios17, older ios versions it is working fine. I am using javascript, angular, ionic with html5 css for developing my app. Please provide solution.
Posted
by
Post not yet marked as solved
0 Replies
543 Views
In my PWA app, I utilize the getUserMedia() API for accessing the camera and also employ HTML audio tags to handle various types of media content. However, since updating to iOS 17, I've encountered an issue where, after granting permission for camera access, audio playback occurs through the earpiece instead of the media speaker. This problem is specific to iOS 17; earlier iOS versions work as expected. My app is developed using a stack that includes JavaScript, Angular, Ionic, HTML5, and CSS. Can you please provide guidance or a solution to address this issue and ensure that audio plays through the media speaker when using the camera on iOS 17?
Posted
by
Post not yet marked as solved
1 Replies
410 Views
One time title was showing below the MarkerAnnotation and I noticed, that once it disappeared and now it is showing inside the marker if you click on it. Is it possible to move it back and show it below the marker? The field, that I am using for this purpose is called "title" navigator.userAgent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36
Posted
by
Post not yet marked as solved
1 Replies
1.5k Views
Recently I noticed that users with Safari 17 have some troubles using my website. I found out that the problem affects only users who use Safari in a private mode. After I dug deeper I realised that for some reason when I execute "window.location" for these users, query parameters do not present there even though they are actually present in the URL. For example, user is on the URL https://mywebsite.com/?code=TULEnfW1zRlqazI7XhM_QV7mxqPr-bV&state=5c5dbb2a-2332-4db7-a657-d2dc713d3e67 But the "window.location.search" returns an empty string. Also, the issue is only reproduced when user is actually redirected to the "broken" page, but it works fine if the user opens the page in a new tab. Issue is reproduced on both iOS and MacOS. I have a suspicion that the issue is somehow related to the recently added feature which prevents cross-site tracking, however, disabling that feature did not help. Does anyone aware of any recent changes to the behaviour of "window.location" in Safari? Thanks!
Posted
by
Post not yet marked as solved
2 Replies
622 Views
With a physical iPhone attached to the dev tools on my laptop, the memory usage of this web page https://nypost.com/2023/10/11/australian-swimmers-almost-walk-into-shark-as-it-swims-close-to-shore/ consistently grows until it reaches the memory limit of the device (in my case, about 1.5GB) The safari dev tools has a memory profiler timeline which breaks down memory usage into categories including "Javascript", "Layers", and "Page"; is there a way to break these down further to individual scripts/resources? I have also tried looking at the Javascript allocations profiler, but the computed heap size reported in its snapshots never comes anywhere close to the 700+ MB of "JavaScript" memory usage reported by the Memory profiler.
Posted
by
Post not yet marked as solved
0 Replies
336 Views
Hi guys I'm developing an extension for Safari using web browser api but Safari does not support management object and getSelft() function. Does anyone know how to check if the extension is installed in development mode? window.browser.management.getSelf(({ installType }) => { if(installType === "development") { // Do some stuff... } })
Posted
by
Post not yet marked as solved
1 Replies
641 Views
I have a website that makes heavy use of the web audio API, the site appears to be broken for all users who have upgraded to iOS 17 (I have verified it no longer works for 17.0.3 and does work for 16.3.1 It also works fine in macOS Safari and all other common desktop browsers that I have tested). I've created a simple test case page here to illustrate the problem: https://oldtime.radio/audio_test.html - clicking 'Play' downloads and plays audio in older iOS but nothing is played for iOS 17. There are no errors in the console so not much to go on. Is this a known bug. Code reproduced below in case folks don't want to click through to an unknown website: const btn = document.getElementById('btn'); btn.addEventListener('click', function() { const audio = new Audio(); audio.crossOrigin = "anonymous"; const AudioContext = window.AudioContext || window.webkitAudioContext, audioCtx = new AudioContext(), audioSrc = audioCtx.createMediaElementSource(audio); audioSrc.connect(audioCtx.destination); audio.addEventListener('canplaythrough', () => { audio.play(); }); audio.src = 'https://archive.org/download/Old_Radio_Adverts_01/OldRadio_Adv--1957_Chevrolet.mp3'; audio.load(); });
Posted
by
Post not yet marked as solved
0 Replies
526 Views
If you refresh the page after initially granting location permissions, you will be prompted for location permissions again and will need to grant permission again. Currently this only occurs on iOS. Is there a way? I launched that web from app and the Safari settings didn't fix the issue. What should I do about this problem? The tested iOS versions are 16.2 and 17. This is the code implemented when retrieving location information. <script> var options = { timeout: 15000, enableHighAccuracy: true, maximumAge: 86400000, }; function success(pos) { var crd = pos.coords; alert('Your current position is:'); alert(`Latitude : `+crd.latitude); alert(`Longitude: `+crd.longitude); }; function error(err) { alert(`ERROR(): `+err.message); }; navigator.geolocation.getCurrentPosition(success, error, options); </script>
Posted
by
Post not yet marked as solved
0 Replies
371 Views
If you refresh the page after initially granting location permissions, you will be prompted for location permissions again and will need to grant permission again. Currently this only occurs on iOS. Is there a way? The tested iOS versions are 16.2 and 17. This is the code implemented when retrieving location information. <script> var options = { timeout: 15000, enableHighAccuracy: true, maximumAge: 86400000, }; function success(pos) { var crd = pos.coords; alert('Your current position is:'); alert(`Latitude : `+crd.latitude); alert(`Longitude: `+crd.longitude); }; function error(err) { alert(`ERROR(): `+err.message); }; navigator.geolocation.getCurrentPosition(success, error, options); </script>
Posted
by
Post not yet marked as solved
0 Replies
746 Views
Hi everyone, I hope this a right place to ask questions like this. I have an app which uses WEBGL scene implemented with three.js. At some point of loading, the app crashes (page reloads), which usually indicates that device ran out of memory reserved for this tab. This webgl scene however is fairly light compared to other scenes that load without any issues. How do I debug this? Is it possible to reallocate more memory before page is loaded, or is there a simple way to reduce memory consumption? I have very limited control over 3d scene, and it doesn't use heavy assets (mostly simple geometry with textures on them)
Posted
by
Post not yet marked as solved
1 Replies
468 Views
Any page that has a JavaScript function named "top()" in it causes JavaScript to fail. The function doesn't need to be called or even contain anything. eg. function top() { } JavaScript just locks up. This affects iOS17.2 and macOS 14.2 If occurs in Safari and any app using WKWebView This is a critical bug that affects sites and apps in the wild. I suggest there is something very wrong with the Javascript engine in general if certain function names can cause such a failure. Does anyone else have other function names that cause this failure?
Posted
by