MCPcopy
hub / github.com/ampproject/amphtml / actionTypeHandler

Function actionTypeHandler

3p/recaptcha.js:147–180  ·  view source on GitHub ↗

* Function to handle executing actions using the grecaptcha Object, * and sending the token back to the parent amp-recaptcha component * * Data Object will have the following fields * action {string} - action to be dispatched with grecaptcha.execute * id {number} - id given to us by a counter i

(win, grecaptcha, data)

Source from the content-addressed store, hash-verified

145 * @param {object} data
146 */
147function actionTypeHandler(win, grecaptcha, data) {
148 doesOriginDomainMatchIframeSrc(win, data)
149 .then(() => {
150 const executePromise = grecaptcha.execute(sitekey, {
151 action: data.action,
152 });
153
154 // .then() promise pollyfilled by recaptcha api script
155 executePromise./*OK*/ then(
156 function (token) {
157 iframeMessagingClient./*OK*/ sendMessage('amp-recaptcha-token', {
158 'id': data.id,
159 'token': token,
160 });
161 },
162 function (err) {
163 let message =
164 'There was an error running ' +
165 'execute() on the reCAPTCHA script.';
166 if (err) {
167 message = err.toString();
168 }
169 user().error(TAG, '%s', message);
170 iframeMessagingClient./*OK*/ sendMessage('amp-recaptcha-error', {
171 'id': data.id,
172 'error': message,
173 });
174 }
175 );
176 })
177 .catch((error) => {
178 dev().error(TAG, '%s', error.message);
179 });
180}
181
182/**
183 * Function to verify our origin domain from the

Callers

nothing calls this directly

Calls 9

userFunction · 0.90
devFunction · 0.90
catchMethod · 0.80
thenMethod · 0.45
executeMethod · 0.45
sendMessageMethod · 0.45
toStringMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected