Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chrome以外で、Vivliostyle-Pubの起動に失敗する #56

Closed
ogwata opened this issue Dec 3, 2020 · 14 comments · Fixed by #308
Closed

Chrome以外で、Vivliostyle-Pubの起動に失敗する #56

ogwata opened this issue Dec 3, 2020 · 14 comments · Fixed by #308
Labels
bug Something isn't working

Comments

@ogwata
Copy link
Member

ogwata commented Dec 3, 2020

  1. ターミナルでリポジトリのディレクトリに移動し、以下のコマンドを実行
$ cd web
$ yarn install
$ yarn dev
  1. Chromeを起動し http://localhost:9990 にアクセスすると、下記のような画面になるので、ユーザ名の部分をクリック(ブラウザの起動以前から、ChromeでGitHubにログインしていた)

スクリーンショット 2020-12-03 17 34 37

  1. Vivliostyle-Pubの起動に成功

スクリーンショット 2020-12-03 17 36 15

  1. 次に、Safariを起動し、同じく http://localhost:9990 にアクセスすると、このような画面になり起動できない

スクリーンショット 2020-12-03 17 37 26

  1. SafariではGitHubにログインしていなかったことを思いだし、あらためてサインイン

スクリーンショット 2020-12-03 17 39 20

  1. その上で http://localhost:9990 にアクセスする

スクリーンショット 2020-12-03 17 39 47

  1. ログイン画面になるので、「Login」をクリック

スクリーンショット 2020-12-03 17 40 22

  1. この画面のまま遷移せず、起動に失敗する

スクリーンショット 2020-12-03 18 20 28

  1. つぎにFirefoxを起動し、GitHubにサインイン

スクリーンショット 2020-12-03 17 42 47

  1. ぶじにGitHubにサインイン成功

スクリーンショット 2020-12-03 17 44 24

  1. 新規タブを開いて http://localhost:9990 にアクセス

スクリーンショット 2020-12-03 17 44 51

  1. ログイン画面になるので「Login」をクリックする

スクリーンショット 2020-12-03 17 44 58

  1. 以下の画面のまま変化せず、Firefoxでも起動に失敗する

スクリーンショット 2020-12-03 17 45 15

@ogwata ogwata added the bug Something isn't working label Dec 3, 2020
@takanakahiko
Copy link
Member

@ogwata これって現状も確認できるバグでしょうか?
確認お願いしたいです!
https://vivliostyle-pub-develop.vercel.app/

@ogwata
Copy link
Member Author

ogwata commented Aug 26, 2021

現時点のバージョンで再現しました。
スクリーンショット動画を撮ってみましたのでご確認ください。

2021-08-26.23.02.44.mov
  1. Chromeでログイン失敗
  2. settings > Applications で全てをdelete、Revoke
  3. Install GitHub Appsをクリックして再インストール
  4. Chromeでログイン成功
  5. Safariでログイン失敗
  6. Appを削除後、再インストールするがログインできない
  7. Firefoxでログイン失敗
  8. Appを削除後、再インストールするがログインできない
  • ログインするアカウントは「ogwata-test」
  • Firefoxでは、当初は別アカウント「OGATA Katsuhiro」でログインしていたが(04:00付近)、「ogwata-test」で再ログインし、失敗しています。

@takanakahiko
Copy link
Member

takanakahiko commented Aug 27, 2021

なるほどです。
現在は図らずとも chrome のみ対応になっていそうですね。
時間ある時に他のブラウザでの問題を調査しようと思います。

@ogwata
Copy link
Member Author

ogwata commented Sep 2, 2021

21時に投稿したコメントは、以前のURL https://vivliostyle-pub-develop-proto.vercel.app/ へのアクセス結果でした。失礼しました。お詫びして削除します。

あらためて3種のブラウザで https://vivliostyle-pub-develop.vercel.app/ にアクセスした動画を投稿します。ただ、状況は悪くなっているように見えます。

  • Firefoxはプレビューが404エラー(00:00-01:03)
  • Chromeもプレビューが404エラー(01:03-02:00)
  • Safariはログインできない(02:00-03:11)

404エラーは3つあるファイルのどれでも発生し、リロードしても、スタイルを変更しても治りません。

Safariでは2回ログインしようとしていますが、ログイン画面に戻ってしまうのは、いずれもログインボタン押下後30秒のようです。

2021-09-02.23.23.32.mov

なお、ChromeでGitHubのセッティングからGitHub Appsや認証情報の削除をしてからログインし直した動画が以下になります。ただ、やはり404エラーは治りませんでした。

2021-09-02.23.31.43.mov

@MurakamiShinyu
Copy link
Member

私も試してみました。

  • Mac
    • Chrome 93.0.4577.63 (Official Build) (arm64) - OK
    • Chrome Canary 95.0.4635.0 (Official Build) canary (arm64) - プレビューが404エラー
    • Firefox 91.0.2 - プレビューが404エラー
    • Firefox Nightly 94.0a1 (2021-09-06)
      • ログインできない
        • Login しようとしても Login に戻る
    • Safari 14.1.2 (16611.3.10.1.6)
      • GitHubリポジトリ一覧が出るがクリックしても開かない
        • GitHubリポジトリ一覧が表示されるとき、JavaScriptコンソールで "SyntaxError: Invalid regular expression: invalid group specifier name" が出ている
  • Windows
    • Chrome 93.0.4577.63(Official Build) - プレビューが404エラー
    • Firefox 91.0.2 - プレビューが404エラー
    • Microsoft Edge 93.0.961.38 (公式ビルド) - プレビューが404エラー

以上テストした範囲では、正常に動くのはMac上の現行バージョンのChromeだけでした。同じChrome 93でもWindowsではプレビューが404エラーになりました。MacのChromeでもCanary版(Chrome 95)では同じくプレビューが404エラーになりました。

@AyumuTakai
Copy link
Contributor

AyumuTakai commented Oct 2, 2021

現在、プレビューが404エラーになる件を調査中です。

簡単なプログラムを作成して検証したところ、
Mac(intel)版Chrome 94では、XMLHttpRequestとFetch APIでfetchイベントが発生せず、Cache Storageにアクセスしないようです。
Image要素やiframe要素のsrcなどにURLを指定するとfetchイベントが発生してキャッシュから読み出せています。

vivliostyle/viewerのnet.tsのajax関数でXMLHttpRequestを使ってソースになるHTMLファイルを読んでいるようですので、
キャッシュに追加したファイルを読み込めていない可能性があります。

ajax関数を改造して先にキャッシュを探す処理を入れてみてはどうでしょうか。

まだ検証が足りていませんが、net.tsのajax関数を以下のように変更したら404エラーは解消されました。

export function ajax(
  url: string,
  opt_type?: XMLHttpRequestResponseType,
  opt_method?: string,
  opt_data?: string,
  opt_contentType?: string,
): Task.Result<Response> {
  const frame: Task.Frame<Response> = Task.newFrame("ajax");
  const request = new XMLHttpRequest();
  const continuation = frame.suspend(request);
  const response: Response = {
    status: 0,
    statusText: "",
    url,
    contentType: null,
    responseText: null,
    responseXML: null,
    responseBlob: null,
  };
  caches
    .match(url)
    .then((res) => {
      if (res) {
        res.text().then((txt) => {
          Logging.logger.warn("caches match", txt);
          response.status = res.status;
          response.statusText = res.statusText;
          response.contentType = res.headers.get("Content-Type");
          response.responseText = txt;
          continuation.schedule(response);
        });
      } else {
        Logging.logger.debug("caches no match");
        request.open(opt_method || "GET", url, true);
        if (opt_type) {
          request.responseType = opt_type;
        }
        request.onreadystatechange = () => {
          if (request.readyState === 4) {
            response.status = request.status;
            response.statusText =
              request.statusText || (request.status == 404 && "Not Found") || "";
            if (response.status == 200 || response.status == 0) {
              if (
                (!opt_type || opt_type === XMLHttpRequestResponseType.DOCUMENT) &&
                request.responseXML &&
                request.responseXML.documentElement.localName != "parsererror"
              ) {
                response.responseXML = request.responseXML;
                response.contentType = (request.responseXML as any).contentType;
              } else if (
                (!opt_type || opt_type === XMLHttpRequestResponseType.DOCUMENT) &&
                request.response instanceof HTMLDocument
              ) {
                response.responseXML = request.response;
                response.contentType = (request.response as any).contentType;
              } else {
                const text = request.response;
                if (
                  (!opt_type || opt_type === XMLHttpRequestResponseType.TEXT) &&
                  typeof text == "string"
                ) {
                  response.responseText = text;
                } else if (!text) {
                  Logging.logger.warn("Unexpected empty success response for", url);
                } else {
                  if (typeof text == "string") {
                    response.responseBlob = makeBlob([text]);
                  } else {
                    response.responseBlob = text as Blob;
                  }
                }
                const contentTypeHeader = request.getResponseHeader("Content-Type");
                if (contentTypeHeader) {
                  response.contentType = contentTypeHeader.replace(/(.*);.*$/, "$1");
                }
              }
            }
            continuation.schedule(response);
          }
        };
        try {
          if (opt_data) {
            request.setRequestHeader(
              "Content-Type",
              opt_contentType || "text/plain; charset=UTF-8",
            );
            request.send(opt_data);
          } else {
            if (
              /^file:|^https?:\/\/[^/]+\.githubusercontent\.com|\.(xhtml|xht|opf)$/i.test(
                url,
              )
            ) {
              // File or GitHub raw URL or .xht(ml) or .opf
              if (
                /\/aozorabunko\/[^/]+\/cards\/[^/]+\/files\/[^/.]+\.html$/.test(url)
              ) {
                // Aozorabunko's (X)HTML support
                request.overrideMimeType("text/html; charset=Shift_JIS");
              } else if (/\.(html|htm)$/i.test(url)) {
                request.overrideMimeType("text/html; charset=UTF-8");
              } else if (/\.(xhtml|xht|xml|opf)$/i.test(url)) {
                request.overrideMimeType("application/xml; charset=UTF-8");
              } else if (/\.(txt|css)$/i.test(url)) {
                request.overrideMimeType("text/plain; charset=UTF-8");
              } else {
                // fallback to HTML
                request.overrideMimeType("text/html; charset=UTF-8");
              }
            } else if (/^data:,(<|%3c)/i.test(url)) {
              request.overrideMimeType("text/html; charset=UTF-8");
            } else if (/^data:,/i.test(url)) {
              request.overrideMimeType("text/plain; charset=UTF-8");
            }
            request.send(null);
          }
        } catch (e) {
          Logging.logger.warn(e, `Error fetching ${url}`);
          continuation.schedule(response);
        }
      }
    })
    .catch((err)=>{ Logging.logger.error('caches error', err); });
  return frame.result();
}

@AyumuTakai
Copy link
Contributor

ブラウザ側でのXMLHttpRequestの実装がfetchイベントを発火させるように変わらない限り、とり急ぎ問題を解決するにはvivliostyle.jsに手を入れるしかないのでは。

方法としては以下の3つがあると思います。

  • 現状のsetup-viewer.jsでパッチを当てる(minifyされたvivliostyle-viewer.jsにパッチを当てるのは大変そう)
  • vivliostyle.jsにPub用のブランチを作成しweb/package.jsonに指定する
  • patch-packageなどでVivliostyle-Pubにyarn install後にパッチを当てる

@MurakamiShinyu
Copy link
Member

この修正で、 Vivliostyle Pub 以外での Vivliostyle.js の利用で問題が起きることがないのであれば、この修正を入れた Vivliostyle.js をリリースしようと思います。

@MurakamiShinyu
Copy link
Member

MurakamiShinyu commented Oct 4, 2021

@AyumuTakai

vivliostyle.js のほうに pull req しませんか。
そうしたら、私の方でマージして、 Vivliostyle.js v2.11.1 をリリースします。

@AyumuTakai
Copy link
Contributor

画像をリポジトリに追加してVFMで表示させる記述をしたところviewer内で404エラーになってしまうため、原因を調べています。
htmlのときのようにViewerが404エラーを表示するのではないので異なる原因によるものだと思います。

このエラーを修正できたらプルリクを投げます。

@AyumuTakai
Copy link
Contributor

キャッシュに保存されているHTMLや画像が404になる原因がService Workerのスコープの問題であることがわかりました。

vivliostyle.jsへの変更は不要で、Pub側での修正だけで済みそうです。#110

お騒がせ致しました。

@ogwata
Copy link
Member Author

ogwata commented Oct 7, 2021

vivliostyle.jsへの変更は不要で、Pub側での修正だけで済みそうです。#110

今気付いたのですが、レビュアーに@spring-rainingさんも加えてもらえませんか。

vivliostyle/community#92 (comment)

@MurakamiShinyu
Copy link
Member

Safari (WebKit) で動かない問題は次のissue:

@MurakamiShinyu
Copy link
Member

#184 (comment)

Safari (WebKit) で "SyntaxError: Invalid regular expression: invalid group specifier name" となる問題は、2023年3月リリースのSafari 16.4で解決しているのでこのissueは閉じます。

Safariでログインできないのは別の理由です。(See #297)

Safari (WebKit)での #138 の問題が解決したあと、Safari および Firefox でログインに失敗するのは以下の問題のためでした:

Starting June 24, 2024, implementing one of the options listed in the linked best practices below will be required for redirect sign-in to work on Google Chrome M115+. This is already required on Firefox 109+ and Safari 16.1+.

この "This is already required on Firefox 109+ and Safari 16.1+" のとおり、FirefoxとSafariでは動きません。そして、Chromeでも対応しないでいると6月24日からは動かなくなるということです。

そこで次のPRでこの対応をしました:

これによって、Chrome以外でもログインできるようになるはずです。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
4 participants