AMP电子邮件表单导致错误[amp-form]表单提交失败:错误:请求viewerRenderTemplate失败:错误:Class $ obf_1008: [英] AMP Email form causes error [amp-form] Form submission failed: Error: Request viewerRenderTemplate failed: Error: Class$obf_1008:

查看:168
本文介绍了AMP电子邮件表单导致错误[amp-form]表单提交失败:错误:请求viewerRenderTemplate失败:错误:Class $ obf_1008:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

该表单在amp游乐场和amp Gmail游乐场中提交情况都很好.当我向自己发送电子邮件并在Gmail中打开它时,动态内容会正确加载,但是在提交表单时会出现以下错误:

The form submits perfectly well in the amp playground and the amp Gmail playground. When I send myself the email and open it in Gmail, the dynamic content loads correctly but on submitting the form, I get the following errors:

Uncaught (in promise) Error: Class$obf_1008: [https://dynamicmail-pa.googleapis.com/v2/xhrs:proxy?alt=protojson] Cg: Unsupported HTTP status: 400: Class$obf_1007: [object Object]

log.js:258 [amp-form] Form submission failed: Error: Request viewerRenderTemplate failed: Error: Class$obf_1008: [https://dynamicmail-pa.googleapis.com/v2/xhrs:proxy?alt=protojson] Cg: Unsupported HTTP status: 400: Class$obf_1007: [object Object]

我知道这很可能是由于CORS造成的.在服务器上,我尝试使用官方文档建议的"@ ampproject/toolbox-cors" 库:

I understand this is likely due to CORS. On my server, I have tried using the "@ampproject/toolbox-cors" library as suggested by the official documentation as so:

const app = express();
const ampCors = require("@ampproject/toolbox-cors");

const cors = require("cors");
app.use(
    ampCors({
        email: true,
        verifyOrigin: false,
        verbose: true
    })
);

我还尝试过手动设置所有标头,如下所示:

I've also tried to manually set all of the headers like so:

const whitelist = [
    "https://playground.amp.dev",
    "https://mail.google.com",
    "https://amp.gmail.dev"
];
const corsOptions = {
    origin: function (origin, callback) {
        console.log("origin", origin);
        if (!origin) {
            return callback(null, true);
        }
        if (whitelist.indexOf(origin) !== -1) {
            return callback(null, true);
        } else {
            return callback(new Error("Origin not in whitelist"));
        }
    }
};

app.use(cors(corsOptions));
app.use((req, res, next) => {
    res.set("AMP-Access-Control-Allow-Source-Origin", "amp@gmail.dev"); //I've changed this to my sender email address when testing from Gmail
    res.set(
        "Access-Control-Expose-Headers",
        "AMP-Access-Control-Allow-Source-Origin"
    );
    res.set("Access-Control-Allow-Credentials", true);
    next();
});

这两种方法都可以在操场上正常工作,但是从Gmail发布时,表格仍然会导致相同的错误.

Both of these work fine in the playground as mentioned but the forms still cause the same error when posted from Gmail.

推荐答案

我已经收到Google某人对此的回答.

I've received an answer from someone at Google about this.

使用提交了解决方案的 enctype = 3D"application/x-www-form-urlencoded" 提交的AMP表单存在一个错误.

There's a bug with AMP forms submitting with enctype=3D"application/x-www-form-urlencoded" which has been submitted for resolution.

在票证上有更新时,我将更新此线程.

I'll update this thread when I have an update on the ticket.

这篇关于AMP电子邮件表单导致错误[amp-form]表单提交失败:错误:请求viewerRenderTemplate失败:错误:Class $ obf_1008:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆