使用location.href从firefox插件调用页面函数不起作用

时间:2018-03-24 17:52:53

标签: javascript firefox-addon firefox-addon-sdk

我尝试从我的firefox扩展content_script中的原始页面调用javascript函数,如下所示:

content_scripts.js

import 'package:angular/angular.dart';
import 'package:angular_components/angular_components.dart';
import 'package:blue_rose_character_creator/src/character/character.dart';
import 'package:googleapis_auth/auth_browser.dart';
import 'package:googleapis/drive/v3.dart';

final identifier = new ClientId(
    "<my-client>.apps.googleusercontent.com",
    null);
const scopes = const [DriveApi.DriveScope];

@Component(
  selector: 'drive',
  templateUrl: 'drive_component.html',
  styleUrls: const ['drive_component.css'],
  directives: const [CORE_DIRECTIVES, materialDirectives],
  providers: const [materialProviders],
)
class DriveComponent {
  @Input() Character character;

  void save() {
    createImplicitBrowserFlow(identifier, scopes)
        .then((BrowserOAuth2Flow flow) {
      // Try getting credentials without user consent.
      // This will succeed if the user already gave consent for this application.
      return flow.clientViaUserConsent(immediate: true).catchError((_) {

        //I've removed the loginButton from the flow, since AngularDart
        //doesn't pass this around.
        //loginButton.text = 'Authorize';
        //return loginButton.onClick.first.then((_) {
        return flow.clientViaUserConsent(immediate: false);
      }, test: (error) => error is UserConsentException);
    });
  }

这在我的Chrome扩展程序中运行良好,但在我的Firefox插件中无效。

是否有类似的解决方案或解决方法从页面调用该功能? 我几个小时以来一直在寻找解决方案而无法让它发挥作用。

希望你能帮助我

1 个答案:

答案 0 :(得分:0)

经过几个小时的搜索后,我找到了一个适合我的解决方案。

Calling webpage JavaScript methods from browser extension