I have a Safari Web Extension that successfully receives a message from a webpage and returns a response.
I now want to add a user interface to the Safari Web Extension. How do I do this?
I have modified the default template code as follow to add an NSAlert for testing. The modal runs, but no alert ever appears, and the code remains stuck at runModal.
What is the correct way to add a UI to a webextension?
- (void)beginRequestWithExtensionContext:(NSExtensionContext *)context {
id message = [context.inputItems.firstObject userInfo][SFExtensionMessageKey];
NSLog(@"Received message from browser.runtime.sendNativeMessage: %@", message);
NSAlert* alert = [[NSAlert alloc]init];
[alert setMessageText:message[@"request"]];
[alert setInformativeText:@"Hello"];
[alert runModal];
NSExtensionItem *response = [[NSExtensionItem alloc] init];
response.userInfo = @{ SFExtensionMessageKey: @{ @"id": message[@"id"], @"uuid": message[@"uuid"], @"contentType": message[@"contentType"], @"response": message[@"request"] } };
[context completeRequestReturningItems:@[ response ] completionHandler:nil];
}
@end