Skip to content
This repository was archived by the owner on Feb 18, 2025. It is now read-only.
Merged
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
23 changes: 12 additions & 11 deletions OnePasswordExtension.m
Original file line number Diff line number Diff line change
Expand Up @@ -517,17 +517,18 @@ - (void)executeFillScript:(NSString *)fillScript inWebView:(id)webView completio
#pragma mark - WebView field collection and filling scripts

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