无法访问页面内容

时间:2018-01-05 14:45:12

标签: javascript google-chrome-extension

尝试按名称获取元素时遇到问题"登录"。如果至少有一个具有此名称的HTML输入,则应返回1。但它不起作用! Chrome控制台无法写入任何错误。

smart.js

public function getOptOut(EmailOptingRequest $request)
{
    $customer = Customer::find(Auth::id());
    $email = $customer['attributes']['Email'];
    $token = "552sg1fw485ww";

    $client = new Client();

    $res = $client->request('GET', 'https://www.example.com/api/Services/Email/Opting', [
        'headers' => [
            'Accept' => 'application/json',
            'Authorization' => 'Bearer ' . $token
        ],
        'email' => $email
    ]);

    $emailToken = json_decode($res->getBody()->getContents(), true)[0]['token'];

    return view('customer.email-opting', array(
        'customer' => $customer,
        'email' => $email,
        'token' => $token,
        'client' => $client,
        'res' => $res,
        'emailToken' => $emailToken
    ));
}

public function postOptOut(EmailOptingRequest $request)
{
    $email_token = $request->emailToken;

    $client = new Client();

    $res = $client->request('POST', 'https://www.example.com/api/Services/Email/Opting', [
        'email_token' => $email_token,
        'marketing' => (int)$request->input('marketing', 0),
        'promotional' => (int)$request->input('promotional', 0),
        'news' => (int)$request->input('news', 0),
        'feedback' => (int)$request->input('feedback', 0)
    ]);

    return redirect('customer')->with('success', 'You will no longer receive email notifications from the categories you unchecked.');
}

的manifest.json

chrome.webNavigation.onCompleted.addListener(function(){
    console.log("And finally " + document.getElementsByName("login").length);
}

谢谢!

2 个答案:

答案 0 :(得分:0)

我认为您应该尝试使用chrome.tabs.onUpdated.addListener()。我正在那样使用它:

chrome.tabs.onUpdated.addListener(
  function (tabId, changeInfo, tab) { 
    if (changeInfo.status == 'complete') {
     ...
    } 
  }
); 

答案 1 :(得分:0)

我认为您应该将这些函数chrome.webNavigation.onCompleted.addListener移动到后台脚本。问题是内容脚本无法处理它。然后,如果您需要从后台脚本发送数据,请使用消息传递。