Currently, I am developing a Safari App Extension with the aim of automating the login process for a Citrix web portal. In my injected JavaScript code, there are two main tasks that need to be accomplished. Firstly, I need to submit an HTML form containing username and password fields, which is working correctly and redirects me to another page with an HTML anchor that requires clicking. However, I am encountering difficulties in programmatically triggering the click event on this HTML anchor link.
// The following code snippet is from the 'script.js' file injected by my Safari App Extension
document.addEventListener("DOMContentLoaded", function(event) {
if (document.URL.includes("IdentityFederationPortal")) {
document.getElementById("UserId").value = "..." // my login
document.getElementById("Password").value = "..." // my password
document.getElementById("submit").click() // <- works correctly
}
// The `.click()` method mentioned above functions properly as it is applied to a form button.
if (document.URL.includes("TPDCWeb")) {
var loginLink = document.querySelector("#plugin-assistance-download > div > div > div > div.footer > a.pluginassistant-skiplink.web-screen-link._ctxstxt_SkipToLogon._ctxsattr_title_SkipToLogonTip");
console.log(loginLink) // console confirms that loginLink contains the correct HTML anchor element
loginLink.click() // unfortunately, this does not work as expected!
}
});
Additional Notes:
The specific HTML for the anchor link that needs to be programmatically clicked is:
. I have limited knowledge about web programming and am unsure about the functionality of this link when clicked by a regular user, especially considering that it appears to lead nowhere and has a<a class="pluginassistant-skiplink web-screen-link _ctxstxt_SkipToLogon _ctxsattr_title_SkipToLogonTip" href="#" title="Click here to skip to log on">Log on</a>
NULL
onClick
property upon inspection.I have come across suggestions indicating that jQuery could be helpful in resolving this issue, but I am uncertain how to inject jQuery into a Safari App Extension script. My attempts thus far have resulted in the error message '
Can't find variable $
' when attempting to utilize jQuery.