Hi,
I’m encountering an unexpected issue in Safari. Specifically, navigator.clipboard.writeText() fails when called from a content script in my extension immediately after sending a message to background.js while it works fine in Chrome and Firefox. Is this expected?
Environment
Safari
18.2 (20620.1.16.11.8)
Technology Preview 210
macOS Sequoia 15.2 (24C101)
Example
This is a minimal reproducible example, which adds a button to example.com:
https://github.com/mshibanami/ClipboarAPIIssueExample
Below is the related code:
// content.js
copyButton.addEventListener('click', async () => {
// 👇️ This call seems to trigger the issue
await chrome.runtime.sendMessage({});
try {
await navigator.clipboard.writeText(text);
alert(`✅ Copied '${text}' to clipboard!`);
} catch (err) {
alert(err + '\n\n' + `navigator.userActivation.isActive: ${navigator.userActivation.isActive}`);
}
});
// background.js
chrome.runtime.onMessage.addListener(() => { });
When I click the button, I expect the text to be copied successfully. However, I receive an error in Safari.:
Interestingly, if I remove chrome.runtime.sendMessage(), the clipboard operation works without any problems. Also, note that navigator.userActivation.isActive is true, which might mean it's not related to the User Activation API.
Misc.
This might be related to another question I posted here:
https://developer.apple.com/forums/thread/772275
WebKit JS
RSS for tagAccess and modify DOM elements within a webpage, including touch events and visual effects, using WebKit JS.
Posts under WebKit JS tag
64 Posts
Sort by:
Post
Replies
Boosts
Views
Activity
Hi,
I'm encountering an issue with the Clipboard API's writeText() method in Safari. It throws a NotAllowedError even when triggered by a user action (selecting an option from a <select> element). Is this expected?
This issue seems specific to Safari, as the same code works perfectly in Firefox and Chrome.
Perhaps I should send feedback to Apple, but I'd like to post it here first in case I misunderstand something.
Problem
In Safari, when I try to copy text to the clipboard using navigator.clipboard.writeText() within an input event listener attached to a <select> element, it fails with the following error:
NotAllowedError: The request is not allowed by the user agent or the platform in the current context, possibly because the user denied permission.
Environment
Safari
18.2 (20620.1.16.11.8)
Technology Preview 210
macOS Sequoia 15.2 (24C101)
Example
I've created a minimal reproducible example on CodePen: https://codepen.io/mshibanami/pen/LEPdxXZ
Here's the relevant JavaScript code from the example:
selectElement.addEventListener('input', async (event) => {
const selectedText = event.target.options[event.target.selectedIndex].text;
try {
await navigator.clipboard.writeText(selectedText);
alert(`Text copied to clipboard: ${selectedText}`);
} catch (err) {
alert('Failed to copy text to clipboard: ' + err);
}
});
Firefox and Chrome handle this code without any issues, successfully copying the text to the clipboard, but not Safari.
Possible Cause
I suspect this issue might be related to WebKit's User Activation API. It seems like Safari is not correctly recognizing the input or change event on a <select> element as a valid user activation for the Clipboard API, even though it is initiated by a user gesture.
Questions
Is this behavior unexpected? Should Safari allow the Clipboard API to work in this context?
(Technically, this might be expected as of now, as such events are not explicitly described in https://webkit.org/blog/13862/the-user-activation-api/.)
Any insights or suggestions would be greatly appreciated. Thanks!
We as a team of engineers work on an app intended to visualize medical images. The type of situations where the app is used involves time critical decision making for acute clinical conditions. Stability of the app and performance are of utmost importance and can directly help timely treatment action. The app we are developing uses multiple libraries and tools like vtk, webgl, opengl, webkit, gl-matrix etc.
The problem specifically can be described as follows, it has been observed that when 3D volume is rendered in the app and we try to rotate the volume the rotation is slow, unresposive and laggy. Specifically, we have noticed that iOS 18.1 the volume rotation is much smoother as compared to latest iOS 18.2. Eariler, we have faced somewhat similar issue with iOS 17 but it got improved in iOS 18.1. This performance regression is affecting the user experience in our healthcare application.
We have taken reference from the cornerstone.js code and you can reproduce the issue using the following example: https://www.cornerstonejs.org/live-examples/volumeviewport3d
Steps to Reproduce:
Load the above mentioned test example on an iPhone running version 18.2 using safari.
Perform volume rendering using the provided dataset.
Measure the time taken by volume for each rotate or drag action.
Repeat the same steps on an iPhone running version 18.1 for comparison.
Additional Information:
Device Model Tested:
iPhone12, iPhone13, iPhone14
iOS Version With Issue:
18.2
18.3(Beta)
I would appreciate any insights or suggestions on how to address this performance regression. If additional information is needed, please let me know.
Thank you.
Hello,
I am experiencing a performance regression in my application when rendering volumes on iPhone. Specifically, I have noticed that iOS version 18.2 takes significantly more time for each render cycle as compared to iOS 18.1.
Details:
Affected Versions:
iOS version 18.2
iOS version 18.1 (baseline for comparison)
Issue Description:
In iOS version 18.2, the time taken to render volumes has increased compared to iOS version 18.1. This performance regression is affecting the user experience in my application.
Test Example:
https://www.cornerstonejs.org/live-examples/volumeviewport3d
Steps to Reproduce:
Load the above test example on an iPhone running version 18.2 using safari.
Perform volume rendering using the provided dataset.
Measure the time taken by volume for each rotate or drag action.
Repeat the same steps on an iPhone running version 18.1 for comparison.
Additional Information:
Device Model Tested:
iPhone12, iPhone13, iPhone14
iOS Version With Issue:
18.2
18.3(Beta)
I would appreciate any insights or suggestions on how to address this performance regression. If additional information is needed, please let me know.
Thank you.
Hi everyone,
I'm facing an issue with accessing device orientation and motion events in Safari on my iPhone (iOS 18). Despite trying several guides and solutions, I cannot find the option to allow access to motion and orientation for websites in the browser settings. I’ve checked privacy settings, and the device is up to date. Can anyone guide me on how to enable this feature in Safari or share any workarounds? Thanks in advance!
Is this technical solution reasonable about WKWebView on cross-domain issues ?
Hi,all
My project use WKWebView to load offline package, such as .html/.css/.js,and also request some resources from remote server to update pages. So there is a cross-domain problem with local file(file://***) and remote domain (https://***), is this following technical solution reasonable to fix this problem:
1. Create a custom URLSchemeHandler which conforms to WKURLSchemeHandler
2.Unify local file and remote domain request to https request
3. Hook WKWebView https request
4. Implement WKURLSchemeHandler delegate method
(void)webView:(WKWebView *)webView startURLSchemeTask:(id)urlSchemeTask {
NSURL *url = urlSchemeTask.request.URL;
if ([url.pathExtension isEqualToString:@"html"]) {
NSData *data = [[NSData alloc] initWithContentsOfFile:localFilePath];
NSMutableDictionary resHeader = [NSMutableDictionary new];
[resHeader setValue:@"" forKey:@"Access-Control-Allow-Origin"];
[resHeader setValue:@"charset=UTF-8" forKey:@"Content-Type"];
[resHeader setValue:@"text/html" forKey:@"Content-Type"];
NSHTTPURLResponse *response = [[NSHTTPURLResponse alloc]
initWithURL:url statusCode:200 HTTPVersion:@"HTTP/1.1" headerFields:resHeader];
[urlSchemeTask didReceiveResponse:response];
[urlSchemeTask didReceiveData:data];
[urlSchemeTask didFinish];
} else {
NSURLSession *defaultSession = [NSURLSession sharedSession];
NSURLSessionTask *dataTask = [defaultSession dataTaskWithRequest:urlSchemeTask.request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
[urlSchemeTask didReceiveResponse:response];
[urlSchemeTask didReceiveData:data];
[urlSchemeTask didFinish];
}];
[dataTask resume];
}
}
Is this technical solution reasonable? and is there any issues that I haven't considered?
Sincerely,
Looking forward to your reply
I am currently publishing an application that uses WebView,
I am currently publishing an application that uses WebView, but I am having trouble with data in LocalStorage sometimes disappearing.
The website displayed in WebView is made with PHP,
By writing the following code in JavaScript,
When WKWebView is opened, localStorage is saved and retrieved.
window.localStorage.setItem('isAlreadyAgree', true);
window.localStorage.getItem('isAlreadyAgree');
The problem is that sometimes this getItem does not get the data.
・This is not reproducible and does not always occur when some process is performed.
・Is it possible that the storage of the application is cleared due to distribution using MDM?
・Is it possible to store too much data in UserDefault, which would cause the LocalStorage space to be overwhelmed and disappear?
I would appreciate any hints you can give me.
Thank you in advance.
The app gets stuck after login on an iOS 18 device. It works in Xcode, but the simulator shows the following console error: IntegrationApp(769,0x1f0094c00) malloc: xzm: failed to initialize deferred reclamation buffer (46).
The specification states that the timestamp property is a DOMHighResTimeStamp which always represents a value in milliseconds. However, in my testing (on iOS as I don't have a mac) the timestamp is given as seconds. This could break compatibility if an app/library is not tested in Safari.
Worse is that the deviation seems to be undocumented as every compatibility chart states full compatibility and defines the property as milliseconds.
Any workaround would also be up to one frame incorrect. So a stutter can affect input accuracy.
I know this might seem small but it could mean that an app or game is unplayable in Safari if it relies on this for input.
When I run the following code in XCode iOS Simulator on Safari (connecting via Safari DevTools):
navigator.serviceWorker.ready.then((reg) => reg.pushManager.subscribe({ userVisibleOnly: true, applicationServiceKey: "..." }).then((sub) => console.log(sub.toJSON())))
I get the response:
{ keys: { p256dh: "", auth: "" } }
But I'm expecting p256dh and auth (and endpoint) to be filled out. Why is it not?
Hello everyone,
in my website I need to give users the ability to choose a color via input type=“color”.
I don't understand why it works fine on desktop (even on Safari for Mac) but doesn't open the color picker on iPhone.
How can I solve this?
Thank you,
Andrea
iOS18 Added support for WebRTC HEVC RFC 7789 RTP Payload Format. (112001659),How can i determine whether iOS 18 WebRTC uses hardware or software decoding for HEVC?
Since iPadOS 18.x WKWebView seems to have a bug within its Fullscreen API (which can be enabled via WKPreferences.isElementFullscreenEnabled). This bug has the effect that websites trying to make an element (for example a video player) fullscreen fail to do so. This does not always happen, most of the time the fullscreen mode does work fine, but sometimes (far too often to be ignored) it does not. If an instance of WKWebView shows this issue, it can not be "fixed" by reloading the page or loading other pages, this issue exists in this instance forever.
My App is a web browser App so I can create and remove WKWebView instance easily (by opening or closing Tabs). And there are times where I never see this bug, and times where ever other tab shows this bug. It's totally unreliable.
The App does not show any issues at all when running under iPadOS 17 or older. The issue is only present under iPadOS 18.x.
After some testing I've found out that when the bug has affected an instance of WKWebView, the JavaScript call element.requestFullscreen() will work if the element is a video element, but does no longer work if it is another element (like a DIV). If an instance of WKWebView is not affected by this bug, element.requestFullscreen() will work for all HTML elements.
Does anyone has experienced this bug as well? And maybe found a workaround? Or maybe found a pattern which helps to find out what exactly is triggering this bug?
Recently, we ran into a bit of a problem when using WKWebView. Sometimes, problems with all pages blank occur which use WKWebView.
I implemented WKNavigationDelegate and found that it stops at
- (void)webView:(WKWebView *)theWebView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler
and it won't call below func forever
- (void)webView:(WKWebView*)theWebView didStartProvisionalNavigation:(WKNavigation*)navigation
I suspected that the render process is terminated and it won't restart.
Then i try to resolve this problem by call reload func
[self.webView reload];
But it didn't work. In The Meanwhile, i got some error message in console
I have tested it in iOS 16 and 17. only iOS 17 got the issue.
Pray for some help. Thanks a lot.
I'm working on a rather complex web application that includes 3D terrain, 2D mapping, and SVG animations. Both Safari and the Swift app I've built using WkWebKit reload the page after some period of time. Safari pops up a small text block that says:
This webpage was reloaded because it was using significant memory.
Yes. That's true. It's also true that the M1 Max Mac was in now way experiencing issues, nor were any of the other web pages running in other tabs or windows.
The memory limit is simply too low for modern web apps. So far I've not found any way to adjust the parameters in Safari or WkWebView.
Apple, help a brother out. It's not 1997 anymore. Web apps are big. And resetting them at some arbitrary point causes more problems that is solves.
Anyone have any suggestions? Quinn, any way (other than casting a stone into the one-way abyss of Radar) of getting help from the big A here?
I'm developing an application that utilizes WKWebView to display a webpage. My goal is to improve the performance and loading speed of this webpage by intercepting specific API calls and providing pre-stored JSON responses directly from within the app, ensuring the webpage renders instantaneously.
The challenge I am encountering is the inability to intercept HTTPS URL schemes directly from WKWebView. Any insights or solutions from the community on how to effectively manage and overwrite these particular network requests would be greatly appreciated.
I'm injecting some javascript into a WKWebview on iOS. At a certain point the web view spits out these warnings into the console and the javascript execution stops.
0x109018c40 - [PID=778] WebProcessProxy::gpuProcessExited: reason=IdleExit
0x109019200 - [PID=779] WebProcessProxy::gpuProcessExited: reason=IdleExit
Failed to terminate process: Error Domain=com.apple.extensionKit.errorDomain Code=18 "(null)" UserInfo={NSUnderlyingError=0x303c3c060 {Error Domain=RBSRequestErrorDomain Code=3 "No such process found" UserInfo={NSLocalizedFailureReason=No such process found}}}
I can't find any solution for this so am looking if anyone has any idea of what to try.
None of the WKWebview delegate functions trigger when this occurs so I can't attempt to reload the webview at this stage
I am trying to access a camera from web view and I'm unable to load the updated UI in web view and web view gets flick for every few seconds. The updated UI has some more functionality, but the web page not getting loaded.
Running a web server on localhost is breaking on the iOS Simulator. It is also blocking me from testing my mobile application.
Full Log:
Full Log
PLATFORM AND VERSION
iOS
Development environment: Other: Xamarin iOS App
Run-time configuration: iOS 14.4.2 and above
DESCRIPTION OF PROBLEM
We are using WKWebView control in our application. It loads a page, wherein there is a code which gets triggered to execute a Synchronous Ajax/XmlHttpRequest. This request needs about 1 min time to complete, but it gets aborted after 10 secs.
Observed in iPhone 6S 14.4.2. Also seen the same behavior in the latest version of iPhone and iPad OS.
Need help on the below points:
How can I extend this timeout?
Making it an Asynchronous call would have regression. Hence the ask for any other alternative to extend this timeout.
STEPS TO REPRODUCE
In the WKWebView have a webpage, which gives a Synchronous ajax/XmlHttpRequest call to a Web API, which takes more than 10 seconds to complete. The Ajax call sample code is as below, which uses jquery:
var startTime = performance.now();
$.ajax({
async: false, // Synchronous ajax call
type: "POST",
url: "http://testsite:8000/api/RunTestTimer",
contentType: "application/json; charset=utf-8",
data: JSON.stringify({
timeInSeconds: 15
}), // timeInSeconds is the parameter name in the Web API, which I used to run a timer on the server-side for the value passed to the ajax call
dataType: "json",
beforeSend: skelta.forms.utilities.addRequestHeaders
})
.done(function (result) {
var endTime = performance.now();
var message = "Request Successful (Time Taken to execute: " + ((endTime - startTime) / 1000).toFixed(3) + " secs; Type: " + "POST" + "; Async: " + "FALSE" + "; Timer: " + "15" + " seconds):" + JSON.stringify(result);
console.log(message);
})
.fail(function (result) {
var endTime = performance.now();
var message = "Request Failed (Time Taken to execute: " + ((endTime - startTime) / 1000).toFixed(3) + " secs; Type: " + "POST" + "; Async: " + "FALSE" + "; Timer: " + "15" + " seconds):" + JSON.stringify(result);
console.log(message);
});