Skip to content
This repository was archived by the owner on Feb 18, 2025. It is now read-only.
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions OnePasswordExtension.m
Original file line number Diff line number Diff line change
Expand Up @@ -516,18 +516,18 @@ - (void)executeFillScript:(NSString *)fillScript inWebView:(id)webView completio

#pragma mark - WebView field collection and filling scripts

static NSString *const OPWebViewCollectFieldsScript = @"document.collect=p;document.elementsByOPID={};\
function p(e,d){function f(a,b){var c=a[b];return'string'==typeof c||'function'==typeof a.getAttribute&&(c=a.getAttribute(b),'string'==typeof c)?c:null}function g(a){var b,c;if(!a)return'';if(a._idCache)return a._idCache;if('BODY'==a.tagName)return a.tagName;b=a.parentNode;if(!b)return'';c=b.childNodes;for(b=0;b<=c.length;b++)if(c[b]==a)return b=g(a.parentNode)+'/'+a.tagName+'['+b+']',a._idCache=b;return''}function q(a){return a.options?(a=Array.prototype.slice.call(a.options).map(function(a){return[k(a.text),a.value]}),\
{options:a}):null}function s(a){var b;for(a=a.parentElement||a.parentNode;a&&'td'!=l(a.tagName);)a=a.parentElement||a.parentNode;if(!a||void 0===a)return null;b=a.parentElement||a.parentNode;if('tr'!=b.tagName.toLowerCase())return null;b=b.previousElementSibling;if(!b||'tr'!=(b.tagName+'').toLowerCase()||b.cells&&a.cellIndex>=b.cells.length)return null;a=b.cells[a.cellIndex];return k(a.innerText||a.textContent)}function w(a){var b=e.documentElement,c=a.getBoundingClientRect(),f=b.getBoundingClientRect(),\
d=c.left-b.clientLeft,b=c.top-b.clientTop;return a.offsetParent?0>d||d>f.width||0>b||b>f.height?t(a):(f=a.ownerDocument.elementFromPoint(d+3,b+3))?'label'===l(f.tagName)?f===x(a):f.tagName===a.tagName:!1:!1}function t(a){for(var b;a!==e&&a;a=a.parentNode)if(b=u.getComputedStyle?u.getComputedStyle(a,null):a.style,'none'===b.display||'hidden'==b.visibility)return!1;return a===e}function x(a){var b=e.querySelector(\"label[for='\"+String.prototype.replace.call(a.id,\"'\",\"\\\\'\")+\"']\")||e.querySelector(\"label[for='\"+\
String.prototype.replace.call(a.name,\"'\",\"\\\\'\")+\"']\");if(b)return b.innerText;for(;a&&a!=e;a=a.parentNode)if('label'===l(a.tagName))return a.innerText;return null}function k(a){return(a=a?l(a).replace(/\\s/mg,'').replace(/[~`!@$%^&*()\\-_+=:;'\"\\[\\]|\\\\,<.>\\/?]/mg,''):null)?a:null}function h(a,b,c){null!==c&&void 0!==c&&(a[b]=c)}function l(a){return'string'===typeof a?a.toLowerCase():(''+a).toLowerCase()}var u=e.defaultView?e.defaultView:window,m=RegExp('(pin|password|passwort|kennwort|passe|contraseña|senha|密码|adgangskode|hasło|wachtwoord)',\
'i'),C=Array.prototype.slice.call(e.querySelectorAll('form')).map(function(a,b){var c={},e='__form__'+b;a.opid=e;c.opid=e;h(c,'htmlName',f(a,'name'));h(c,'htmlID',f(a,'id'));h(c,'htmlAction',r(f(a,'action')));h(c,'htmlMethod',f(a,'method'));return c}),z=Array.prototype.slice.call(e.querySelectorAll('input, select')).map(function(a,b){var c={},d='__'+b;e.elementsByOPID[d]=a;a.opid=d;c.opid=d;c.elementNumber=b;c.maxLength=-1==a.maxLength?999:a.maxLength;c.visible=t(a);c.viewable=w(a);c.parentId=g(a.parentNode);\
h(c,'htmlID',f(a,'id'));h(c,'htmlName',f(a,'name'));h(c,'htmlClass',f(a,'class'));if('hidden'!=l(a.type)){h(c,'label-tag',k(x(a)));h(c,'label-data',k(f(a,'data-label')));h(c,'label-aria',k(f(a,'aria-label')));h(c,'label-top',s(a));for(var d=[],n=a;n&&n.nextSibling;){n=n.nextSibling;if(v(n))break;y(d,n)}d=k(d.join(''));h(c,'label-right',d);d=[];A(a,d);d=k(d.reverse().join(''));h(c,'label-left',d);h(c,'placeholder',f(a,'placeholder'))}h(c,'rel',f(a,'rel'));h(c,'type',l(f(a,'type')));a:switch(l(a.type)){case 'checkbox':d=\
a.checked?'✓':'';break a;default:d=a.value}h(c,'value',d);h(c,'checked',a.checked);h(c,'autoCompleteType',a.getAttribute('x-autocompletetype')||a.getAttribute('autocompletetype')||a.getAttribute('autocomplete'));h(c,'selectInfo',q(a));h(c,'aria-hidden','true'==a.getAttribute('aria-hidden'));h(c,'aria-disabled','true'==a.getAttribute('aria-disabled'));h(c,'aria-haspopup','true'==a.getAttribute('aria-haspopup'));a.form&&(c.form=a.form.opid);d=(m.test(c.value)||m.test(c.htmlID)||m.test(c.htmlName)||\
m.test(c.placeholder)||m.test(c['label-tag'])||m.test(c['label-data'])||m.test(c['label-aria']))&&('text'==c.type||'password'==c.type&&!c.visible);c.fakeTested=d;return c});z.filter(function(a){return a.fakeTested}).forEach(function(a){var b=e.elementsByOPID[a.opid];b.getBoundingClientRect();!b||b&&'function'!==typeof b.click||b.click();b.focus();B(b,'keydown');B(b,'keyup');B(b,'keypress');b.click&&b.click();a.postFakeTestVisible=t(b);a.postFakeTestViewable=w(b);a=b.ownerDocument.createEvent('HTMLEvents');\
var c=b.ownerDocument.createEvent('HTMLEvents');B(b,'keydown');B(b,'keyup');B(b,'keypress');c.initEvent('input',!0,!0);b.dispatchEvent(c);a.initEvent('change',!0,!0);b.dispatchEvent(a);b.blur()});return{documentUUID:d,title:e.title,url:u.location.href,forms:function(a){var b={};a.forEach(function(a){b[a.opid]=a});return b}(C),fields:z,collectedTimestamp:(new Date).getTime()}};document.elementForOPID=D;function B(e,d){var f;f=e.ownerDocument.createEvent('KeyboardEvent');f.initKeyboardEvent?f.initKeyboardEvent(d,!0,!0):f.initKeyEvent&&f.initKeyEvent(d,!0,!0,null,!1,!1,!1,!1,0,0);e.dispatchEvent(f)}function y(e,d){var f;f='';3===d.nodeType?f=d.nodeValue:1===d.nodeType&&(f=d.innerText||d.textContent);var g=null;f&&(g=f.toLowerCase().replace(/\\s/mg,'').replace(/[~`!@$%^&*()\\-_+=:;'\"\\[\\]|\\\\,<.>\\/?]/mg,''),g=0<g.length?g:null);(f=g)&&e.push(f)}\
function v(e){var d;e&&void 0!==e?(d='select option input form textarea iframe button body head'.split(' '),e?(e=e?(e.tagName||'').toLowerCase():'',d=d.constructor==Array?0<=d.indexOf(e):e===d):d=!1):d=!0;return d}function A(e,d,f){var g;for(f||(f=0);e&&e.previousSibling;){e=e.previousSibling;if(v(e))return;y(d,e)}if(e&&0===d.length){for(g=null;!g;){e=e.parentElement||e.parentNode;if(!e)return;for(g=e.previousSibling;g&&!v(g)&&g.lastChild;)g=g.lastChild}v(g)||(y(d,g),0===d.length&&A(g,d,f+1))}}\
function D(e){var d;if(void 0===e||null===e)return null;try{var f=Array.prototype.slice.call(document.querySelectorAll('input, select')),g=f.filter(function(d){return d.opid==e});if(0<g.length)d=g[0],1<g.length&&console.warn('More than one element found with opid '+e);else{var q=parseInt(e.split('__')[1],10);isNaN(q)||(d=f[q])}}catch(s){console.error('An unexpected error occurred: '+s)}finally{return d}};var E=/^[\\/\\?]/;function r(e){if(!e)return null;if(0==e.indexOf('http'))return e;var d=window.location.protocol+'//'+window.location.hostname;window.location.port&&''!=window.location.port&&(d+=':'+window.location.port);e.match(E)||(e='/'+e);return d+e};\
static NSString *const OPWebViewCollectFieldsScript = @"document.collect=n;document.elementsByOPID={};\
function n(d,e){function f(a,c){var b=a[c];return'string'==typeof b||'function'==typeof a.getAttribute&&(b=a.getAttribute(c),'string'==typeof b)?b:null}function g(a){var c,b;if(!a)return'';if(a._idCache)return a._idCache;if('BODY'==a.tagName)return a.tagName;c=a.parentNode;if(!c)return'';b=c.childNodes;for(c=0;c<=b.length;c++)if(b[c]==a)return c=g(a.parentNode)+'/'+a.tagName+'['+c+']',a._idCache=c;return''}function p(a){return a.options?(a=Array.prototype.slice.call(a.options).map(function(a){var b=a.text,\
b=b?k(b).replace(/\\s/mg,'').replace(/[~`!@$%^&*()\\-_+=:;'\"\\[\\]|\\\\,<.>\\/?]/mg,''):null;return[b?b:null,a.value]}),{options:a}):null}function r(a){var c;for(a=a.parentElement||a.parentNode;a&&'td'!=k(a.tagName);)a=a.parentElement||a.parentNode;if(!a||void 0===a)return null;c=a.parentElement||a.parentNode;if('tr'!=c.tagName.toLowerCase())return null;c=c.previousElementSibling;if(!c||'tr'!=(c.tagName+'').toLowerCase()||c.cells&&a.cellIndex>=c.cells.length)return null;a=c.cells[a.cellIndex];return a.innerText||\
a.textContent}function v(a){var c=d.documentElement,b=a.getBoundingClientRect(),f=c.getBoundingClientRect(),e=b.left-c.clientLeft,c=b.top-c.clientTop;return a.offsetParent?0>e||e>f.width||0>c||c>f.height?s(a):(f=a.ownerDocument.elementFromPoint(e+3,c+3))?'label'===k(f.tagName)?f===w(a):f.tagName===a.tagName:!1:!1}function s(a){for(var c;a!==d&&a;a=a.parentNode)if(c=t.getComputedStyle?t.getComputedStyle(a,null):a.style,'none'===c.display||'hidden'==c.visibility)return!1;return a===d}function w(a){function c(a){return String.prototype.replace.call(a,\
\"'\",\"\\\\'\")}var b;if(c(a.id)&&(b=d.querySelector(\"label[for='\"+c(a.id)+\"']\"))||c(a.name)&&(b=d.querySelector(\"label[for='\"+c(a.name)+\"']\")))return b.innerText;for(;a&&a!=d;a=a.parentNode)if('label'===k(a.tagName))return a.innerText;return null}function h(a,c,b){null!==b&&void 0!==b&&(a[c]=b)}function k(a){return'string'===typeof a?a.toLowerCase():(''+a).toLowerCase()}var t=d.defaultView?d.defaultView:window,l=RegExp('(pin|password|passwort|kennwort|passe|contraseña|senha|密码|adgangskode|hasło|wachtwoord)',\
'i'),B=Array.prototype.slice.call(d.querySelectorAll('form')).map(function(a,c){var b={},d='__form__'+c;a.opid=d;b.opid=d;h(b,'htmlName',f(a,'name'));h(b,'htmlID',f(a,'id'));h(b,'htmlAction',q(f(a,'action')));h(b,'htmlMethod',f(a,'method'));return b}),y=Array.prototype.slice.call(d.querySelectorAll('input, select')).map(function(a,c){var b={},e='__'+c;d.elementsByOPID[e]=a;a.opid=e;b.opid=e;b.elementNumber=c;b.maxLength=-1==a.maxLength?999:a.maxLength;b.visible=s(a);b.viewable=v(a);b.parentId=g(a.parentNode);\
h(b,'htmlID',f(a,'id'));h(b,'htmlName',f(a,'name'));h(b,'htmlClass',f(a,'class'));if('hidden'!=k(a.type)){h(b,'label-tag',w(a));h(b,'label-data',f(a,'data-label'));h(b,'label-aria',f(a,'aria-label'));h(b,'label-top',r(a));for(var e=[],m=a;m&&m.nextSibling;){m=m.nextSibling;if(u(m))break;x(e,m)}h(b,'label-right',e.join(''));e=[];z(a,e);e=e.reverse().join('');h(b,'label-left',e);h(b,'placeholder',f(a,'placeholder'))}h(b,'rel',f(a,'rel'));h(b,'type',k(f(a,'type')));a:switch(k(a.type)){case 'checkbox':e=\
a.checked?'✓':'';break a;default:e=a.value}h(b,'value',e);h(b,'checked',a.checked);h(b,'autoCompleteType',a.getAttribute('x-autocompletetype')||a.getAttribute('autocompletetype')||a.getAttribute('autocomplete'));h(b,'selectInfo',p(a));h(b,'aria-hidden','true'==a.getAttribute('aria-hidden'));h(b,'aria-disabled','true'==a.getAttribute('aria-disabled'));h(b,'aria-haspopup','true'==a.getAttribute('aria-haspopup'));a.form&&(b.form=a.form.opid);e=(l.test(b.value)||l.test(b.htmlID)||l.test(b.htmlName)||\
l.test(b.placeholder)||l.test(b['label-tag'])||l.test(b['label-data'])||l.test(b['label-aria']))&&('text'==b.type||'password'==b.type&&!b.visible);b.fakeTested=e;return b});y.filter(function(a){return a.fakeTested}).forEach(function(a){var c=d.elementsByOPID[a.opid];c.getBoundingClientRect();!c||c&&'function'!==typeof c.click||c.click();c.focus();A(c,'keydown');A(c,'keyup');A(c,'keypress');c.click&&c.click();a.postFakeTestVisible=s(c);a.postFakeTestViewable=v(c);a=c.ownerDocument.createEvent('HTMLEvents');\
var b=c.ownerDocument.createEvent('HTMLEvents');A(c,'keydown');A(c,'keyup');A(c,'keypress');b.initEvent('input',!0,!0);c.dispatchEvent(b);a.initEvent('change',!0,!0);c.dispatchEvent(a);c.blur()});return{documentUUID:e,title:d.title,url:t.location.href,forms:function(a){var c={};a.forEach(function(a){c[a.opid]=a});return c}(B),fields:y,collectedTimestamp:(new Date).getTime()}};document.elementForOPID=C;function A(d,e){var f;f=d.ownerDocument.createEvent('KeyboardEvent');f.initKeyboardEvent?f.initKeyboardEvent(e,!0,!0):f.initKeyEvent&&f.initKeyEvent(e,!0,!0,null,!1,!1,!1,!1,0,0);d.dispatchEvent(f)}function x(d,e){var f;f='';3===e.nodeType?f=e.nodeValue:1===e.nodeType&&(f=e.innerText||e.textContent);var g=null;f&&(g=f.trim(),g=0<g.length?g:null);(f=g)&&d.push(f)}\
function u(d){var e;d&&void 0!==d?(e='select option input form textarea iframe button body head'.split(' '),d?(d=d?(d.tagName||'').toLowerCase():'',e=e.constructor==Array?0<=e.indexOf(d):d===e):e=!1):e=!0;return e}function z(d,e,f){var g;for(f||(f=0);d&&d.previousSibling;){d=d.previousSibling;if(u(d))return;x(e,d)}if(d&&0===e.length){for(g=null;!g;){d=d.parentElement||d.parentNode;if(!d)return;for(g=d.previousSibling;g&&!u(g)&&g.lastChild;)g=g.lastChild}u(g)||(x(e,g),0===e.length&&z(g,e,f+1))}}\
function C(d){var e;if(void 0===d||null===d)return null;try{var f=Array.prototype.slice.call(document.querySelectorAll('input, select')),g=f.filter(function(e){return e.opid==d});if(0<g.length)e=g[0],1<g.length&&console.warn('More than one element found with opid '+d);else{var p=parseInt(d.split('__')[1],10);isNaN(p)||(e=f[p])}}catch(r){console.error('An unexpected error occurred: '+r)}finally{return e}};var D=/^[\\/\\?]/;function q(d){if(!d)return null;if(0==d.indexOf('http'))return d;var e=window.location.protocol+'//'+window.location.hostname;window.location.port&&''!=window.location.port&&(e+=':'+window.location.port);d.match(D)||(d='/'+d);return e+d};\
(function collect(uuid) { var pageDetails = document.collect(document, uuid); return JSON.stringify(pageDetails); })('uuid');";

static NSString *const OPWebViewFillScript = @"var f=!0,h=!0;document.fill=k;\
Expand Down